how to set PHP default exception handler

112 views
asked Apr 2, 2012 in General by chris (500 points)
Hi

How can I set the default PHP exception handler?

thanks

1 Answer

0 like 0 dislike
answered Apr 2, 2012 by lionhost (4,060 points)
hey Chris

you can use the following code

 set_exception_handler (  $exception_handler )

This function must be defined before calling set_exception_handler(). This handler function needs to accept one parameter, which will be the exception object that was thrown.

set_exception_handler() example
<?php
function exception_handler($exception) {
  echo "Uncaught exception: " , $exception->getMessage(), "\n";
}

set_exception_handler('exception_handler');

throw new Exception('Uncaught Exception');
echo "Not Executed\n";
?>
...