问题
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