我在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: ...
编辑:
这有效:
$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'); } });
解决方法
$router->bind('user',function ($value) { try{ throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException); }catch(\Exception $e){ exit('nott'); } });
要么
use Exception; //on top $router->bind('user',function ($value) { try{ throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException); }catch(Exception $e){ exit('nott'); } });
我想现在你明白你错过了什么.