Another approach in which you can wrap your Laravel exception handler with your own is to convert the new type of error to an Exception instance before moving on to Laravel.
Create a class below 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 beginning of config / app.php, you can register the wrapper class as the default error handler:
$existing = set_exception_handler( ['Some\Namespace\ErrorWrapper', 'handleException']); ErrorWrapper::setPreviousExceptionHandler( $existing );
Mikeh
source share