【发布时间】:2018-01-27 04:20:06
【问题描述】:
当找不到路由时,我正在尝试找到一种自定义 Laravel 5.4 错误处理的方法。 在我的 web.php 中有一条路径定义不正确(故意用于测试目的)。我已经将它包装在一个 try...catch 块中并抛出了我自己的自定义异常 RoutesException:
try {
Route::get('terms_rop_labels/view', 'LRChildController@view');
}catch (NotFoundHttpException $ex) {
throw new RoutesException('terms_rop_labels/view');
}
然后在 app\Exceptions\Handler.php 我试图在测试视图中捕获异常:
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);
}
谁能解释为什么处理程序会捕获 NotFoundHttpException 而不是我的自定义 RoutesException?
【问题讨论】:
标签: php laravel-5.4