Can I disable error/exception handling in Silex? Can I disable error/exception handling in Silex? symfony symfony

Can I disable error/exception handling in Silex?


I know the option the (b) you can entirely disable Silex app error handler and after that, your custom error handler should work fine as you defined it.

Entirely disabled Silex error handler:

$app['exception_handler']->disable();

So, It will be like:

require_once  'Exception.php'; # Load the class$handler = new ErrorHandler(); # Initialize/Register it$app = new \Silex\Application();$app->get('/', function () use ($app) {    nonexistentfunction();      trigger_error("example");    throw new \Exception("example");});$app->run();


Please note that ExceptionHandler::disable() has been deprecated in 1.3 and removed in 2.0. So:

In Silex before 2.0:

$app['exception_handler']->disable();

In Silex 2.0+:

unset($app['exception_handler']);


See Silex doc

Seemingly, you need to register an ExceptionHandler as well. Silex will turn fatal errors to exceptions in order to deal with them. Also, if I remember correctly, exceptions of this kind will be caught when 'thrown' inside controllers and middlewares (at least before middleware), but not inside models.

At the end, you can add the following to work with handling things.

// register generic error handler (this will catch all exceptions)$app->error(function (\Exception $e, $exceptionCode) use ($app) {    //if ($app['debug']) {    //    return;    //}    return \Service\SomeHelper::someExceptionResponse($app, $e);});return $app;

I hope that helped a little.