There's another approach where you can wrap the Laravel exception handler with your own, convert the new Error type to an Exception instance before passing back to Laravel.
Create the below class somewhere in your application:
namespace Some\Namespace;
use Error;
use Exception;
class ErrorWrapper
{
private static $previousExceptionHandler;
public static function setPreviousExceptionHandler($previousExceptionHandler)
{
self::$previousExceptionHandler = $previousExceptionHandler;
}
public static function handleException($error)
{
if (!self::$previousExceptionHandler) {
return;
}
$callback = self::$previousExceptionHandler;
if ($error instanceof Error) {
$callback(new Exception($error->getMessage(), $error->getCode()));
}
else {
$callback($error);
}
}
}
At the start of config/app.php, you can then register the wrapper class as the default error handler:
$existing = set_exception_handler(
['Some\Namespace\ErrorWrapper', 'handleException']);
ErrorWrapper::setPreviousExceptionHandler( $existing );