- set_exception_handler: documentation ( source)
- set_error_handler: documentation ( source)
<?php
set_error_handler(function($num, $msg, $file, $line)
{
// Convert to exceptions
throw new ErrorException($msg, 0, $num, $file, $line);
});
set_exception_handler(function($e)
{
// Print or log to file
echo get_class($e).': '.$e->getMessage().' ['.$e->getFile().':'.$e->getLine().']';
});
try
{
// Will be caught
echo array();
}
catch(ErrorException $e) {}
// Will not be caught
echo array();