Created
June 13, 2013 03:07
-
-
Save phybros/5770952 to your computer and use it in GitHub Desktop.
Just playing around finding the nicest ways to trap errors in 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 | |
header("Content-Type: text/plain"); | |
function my_error_handler($num, $err, $file, $line) { | |
echo "Error Occurred: $err\n"; | |
} | |
set_error_handler('my_error_handler', E_ALL); | |
try { | |
echo "Hello World\n"; | |
echo $test; // undeclared variable | |
$foo = array(); // this is ok | |
echo $foo['bar']; // no such index "bar" | |
throw new RuntimeException("This is an exception\n"); | |
} catch(Exception $e) { | |
echo "Exception Occurred: " . $e->getMessage(); | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment