Overriding the default error handler in PHP

Overriding the default error handler in PHP

Last updated:
set_error_handler(
function($severity, $message, $filename, $lineno) {
             if (error_reporting() == 0) {
                 return;
             }
             if (error_reporting() & $severity) {
                 throw new CustomException();
             }
         });
//some code...
restore_error_handler();

This can be used to catch all errors (even notices and warnings) and handle them the way you want to