error-handlingnoticesymfony4

Handle notice in production with Symfony 4


I'm trying the new Symfony 4 and Sentry error tracking.

On dev env, notice and exception are handled the same way with a nice screen thanks to the Debug class.

On prod env, exception triggers the nice error page and a log entry in Sentry. But notices do not trigger this nice page but the code keeps going after the notice: is there a different handling process in prod env for notice?

Something strange: in prod this notice is reported as an ErrorException exception which means that the notice is turned into exception at some point.

Thank you for your help!


Solution

  • Turning an error into an exception depends on this parameter https://symfony.com/doc/current/reference/configuration/framework.html#throw which defaults to kernel.debug which is off in prod env.

    So you can change this framework.php_errors.throw to true and keep kernel.debug to false in prod env which solved my issue.