Skip to content

Instantly share code, notes, and snippets.

@tieutantan
Created September 29, 2018 15:26
Show Gist options
  • Save tieutantan/6cf24cb311ea5fa37f06ac11cbafcbfb to your computer and use it in GitHub Desktop.
Save tieutantan/6cf24cb311ea5fa37f06ac11cbafcbfb to your computer and use it in GitHub Desktop.
PHP custom exceptions for catch "Notice" errors
<?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