Silex Exception handler

久未见 提交于 2020-01-03 05:14:03

问题


I have big problem I don't know why exceptions are not catch by silex exception handler ?

My simple Code looks like this:

<?php

use Silex\Application;

use Silex\Provider\ValidatorServiceProvider;
use Silex\Provider\FormServiceProvider;
use Symfony\Component\HttpFoundation\Request;

$app = new Application();

// SPL Logic Exceptions
// Handle other exception as 500 errors
$app->error(function (\Exception $e, $code) {
exit('asd');
});
throw new Exception('test');
return $app;

And the result is:

Fatal error: Uncaught exception 'Exception' with message 'test'


回答1:


The error listener is only able to catch exceptions thrown from within a controller or a before middleware. Here's an example that works:

$app = new Silex\Application();

$app->error(function (\Exception $e, $code) {
    exit('asd');
});

$app->before(function ($request) {
    throw new Exception('test');
});

$app->run();


来源:https://stackoverflow.com/questions/20311508/silex-exception-handler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!