Change the below line from your app.php
$app->singleton( App\Exceptions\Handler::class );
to:
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
EDIT
The reason why the interface is required in the above exception handler binding is, when an exception is thrown while processing a Route, the below function is invoked to process that exception.
protected function handleException($passable, Exception $e)
{
if (! $this->container->bound(ExceptionHandler::class) || ! $passable instanceof Request) {
throw $e;
}
$handler = $this->container->make(ExceptionHandler::class);
$handler->report($e);
return $handler->render($passable, $e);
}
The if condition checks whether or not the container has a binding for the ExceptionHandler class. And if there is a binding, then the exception will be passed on to that exception handler class to be further handled. If there is no binding declared, then the exception will be re-thrown. Here the binding is checked for Illuminate\Contracts\Debug\ExceptionHandler
. That's why when you directly bind using App\Exceptions\Handler::class
, the exception is not caught by your exception handler.