I have code in RouteServiceProvider:
$router->bind('user', function ($value) {
try{
throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
}catch(Exception $e){
exit('nott');
}
});
and I don not geting output
nott
I am getting
Sorry, the page you are looking for could not be found.
NotFoundHttpException in RouteServiceProvider.php line 75:
...
EDITED: This works:
$router->bind('user', function ($value) {
try{
throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
}catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
exit('addd');
}
});
But this not works:
$router->bind('user', function ($value) {
try{
return (new User)->findOrFail(122);
}catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
exit('addd');
}
});
Exceptionclass; you should instead do a catch on the specific type(s) of exception that you anticipate getting. (btw: the practice of catching the generalExceptionclass is jokingly called "Pokemon exception handling" -- because you're gonna catch 'em all)usethem, and then you won't need the namespace. (the same applies to the Symphony exception class you're using, and to any other class; you can have ausestatement for them at the top of your class, then you don't need to give the full namespace in your code body. Much neater.