0
當用戶嘗試不存在的路由時,我的站點正在記錄未捕獲的異常。日誌看起來像這樣:爲什麼「找不到路線」在Silex中有未捕獲的異常?
[2013-05-30 15:47:38] myapp.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /a/made/up/url" (uncaught exception) at /home/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 92 [] []
這是正常的嗎?或者有什麼方法可以捕捉異常?
我的錯誤處理代碼如下所示:
$app->error(function (\Exception $e, $code) use ($app) {
$app['monolog']->addDebug($e);
// Some app-specific code
$globals = $app['select_globals']();
switch ($code) {
case 404:
return $app['twig']->render('404.phtml', array('globals' => $globals));
break;
default:
return $app['twig']->render('error.phtml', array('globals' => $globals));
}
});
'$ app-> abort(404)'是另一種方式。 – Maerlyn