Well in the custom framework, both of these work:
if ($e instanceof Exception) {
self::newMessage($e);
}
if ($e instanceof Throwable) {
self::newThrowMessage($e); // messages if throwable
}
But the top one always works first, I think since Exception implements the Throwable interface, and that's direct from the php manual, I can just use the top block of code.
I commented one out then the other, both work the same.
Edit:
Tried two more things:
1
public static function exceptionHandler($e)
{
if (!$e instanceof Exception || !$e instanceof Throwable) {
self::newMessage('Exception occured');
}
if ($e instanceof Throwable) {
self::newThrowMessage($e);
} elseif ($e instanceof Exception) {
self::newMessage($e);
} else {
self::newMessage('Whoops');
}
}
The Throwable gets called.
And since I am using instanceof I need at top:
use Throwable;
use Exception;
2 then tried:
public static function exceptionHandler($e)
{
self::newMessage($e);
}
No "use" statement needed.
This also works.
So I still don't understand the using of Throwable in laravel now, when both error and exception already implement the Throwable interface. PHP itself takes care of it.
But any thoughts on setting up custom error and exception handlers in php 7.4 will be appreciated.