I'm trying to find a way of customising the error handling of Laravel 5.4 when a route can't be found. In my web.php there is a route incorrectly defined (deliberately for testing purposes). I have wrapped it in a try...catch block and thrown my own custom exception RoutesException:
try {
Route::get('terms_rop_labels/view', 'LRChildController@view');
}catch (NotFoundHttpException $ex) {
throw new RoutesException('terms_rop_labels/view');
}
Then in app\Exceptions\Handler.php I am trying to catch the exception in a test view:
if ($exception instanceof NotFoundHttpException) {
$parameters = [
'message'=> 'NotFoundHttpException'
];
return response()->view('errors.test', $parameters, 500);
}
if ($exception instanceof RoutesException) {
$parameters = [
'message'=> 'RoutesException'
];
return response()->view('errors.test', $parameters, 500);
}
Can anyone explain why the handler catches a NotFoundHttpException and not my custom RoutesException?