Skip to content

Instantly share code, notes, and snippets.

@phybros
Created June 13, 2013 03:07
Show Gist options
  • Save phybros/5770952 to your computer and use it in GitHub Desktop.
Save phybros/5770952 to your computer and use it in GitHub Desktop.
Just playing around finding the nicest ways to trap errors in PHP
<?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