Created
September 29, 2018 15:26
-
-
Save tieutantan/6cf24cb311ea5fa37f06ac11cbafcbfb to your computer and use it in GitHub Desktop.
PHP custom exceptions for catch "Notice" errors
This file contains hidden or 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 // https://stackoverflow.com/a/5373824 | |
set_error_handler('exceptions_error_handler'); | |
function exceptions_error_handler($severity, $message, $filename, $lineno) { | |
if (error_reporting() == 0) { | |
return; | |
} | |
if (error_reporting() & $severity) { | |
throw new ErrorException($message, 0, $severity, $filename, $lineno); | |
} | |
} | |
$a[1] = 'jfksjfks'; | |
try { | |
$b = $a[0]; | |
} catch (Exception $e) { | |
echo "jsdlkjflsjfkjl"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment