我在RouteServiceProvider中有代码:
$router->bind('user', function ($value) {
try{
throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
}catch(Exception $e){
exit('nott');
}
});
我不知道输出
nott
我正在
Sorry, the page you are looking for could not be found.
NotFoundHttpException in RouteServiceProvider.php line 75:
...
EDITED: 这有效:
$router->bind('user', function ($value) {
try{
throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
}catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
exit('addd');
}
});
但这不起作用:
$router->bind('user', function ($value) {
try{
return (new User)->findOrFail(122);
}catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
exit('addd');
}
});
答案 0 :(得分:8)
$router->bind('user', function ($value) {
try{
throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
}catch(\Exception $e){
exit('nott');
}
});
OR
use Exception; //on top
$router->bind('user', function ($value) {
try{
throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
}catch(Exception $e){
exit('nott');
}
});
我想现在你明白你错过了什么。