0

I am working on a Symfony project and I am trying to create user-friendly error pages for the production environment. To do this, I have overridden the twig.exception_controller parameter. That process is described in the Symfony Documentation. In overriding the exception controller, I have been able to create custom error pages for instances were no routes exist, or an uncaught exception in thrown. I have not been able to get this to work with fatal errors, and that is what my question is about.

Is it possible to catch/handle fatal errors in Symfony? I am not attempting to continue running the application (as the answerer of this question suggests) when a fatal error occurs. I would simply like to show an error page, aside from the standard one which has the function-call stack trace.

I attempted to set the shutdown function using register_shutdown_function, but that did not prevent the default error page (with stack trace) from displaying.

Thanks!

Community
  • 1
  • 1
  • What do you exactly mean with fatal errors? Normally errors that crash the application get error code 500 Bad request, which can be handled with the exception_controller – Maxim Jun 23 '14 at 17:42
  • For example, if there is a call to an undefined method, a `FatalErrorException` is thrown. This exception does not get handled by the `exception_controller`, and I am not sure why. All other exceptions are being handled by the `exception_controller`. – Alec Carpenter Jun 23 '14 at 18:04

2 Answers2

0

you can put your proccesses that might fail into a try block

try {
  // assert this fails because you have some buggy code here
  $foos=$fooService->getFoosByDateTime(); 

}catch(\Exception $e){
  //you can catch the exception 
  $exceptionMessage= $e->getMessage();
  $this->redirect("your_custom_route_to_error_page",{"error":$exceptionMessage});
}
john Smith
  • 17,409
  • 11
  • 76
  • 117
0

You could enable catching Fatal errors and converting them into Exceptions, shown in Debug Component.

// If I remember correct Symfony Fullstack already does this http://symfony.com/doc/current/components/debug/introduction.html

Then you could write a own Exception Handler, which catches and handles the exception in a user friendly way.

Nextar
  • 1,088
  • 2
  • 12
  • 26