Created
June 14, 2017 14:41
-
-
Save Veve2/f080f5382d98535d5ad27c6961eb71fb to your computer and use it in GitHub Desktop.
Error to Exception error_handler for PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function exception_error_handler($severity, $message, $file, $line) { | |
if (!(error_reporting() & $severity)) { | |
// This error code is not included in error_reporting | |
return; | |
} | |
throw new ErrorException($message, 0, $severity, $file, $line); | |
} | |
set_error_handler("exception_error_handler"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of use (after including/inserted at top the code):
Another use is to catch file_get_content errors (uncatchable) by converting them to exceptions (catchable)