You can also set your error handler as an anonymous function that calls an Exception and use a try / catch on that exception.
set_error_handler(
create_function(
'$severity, $message, $file, $line',
'throw new ErrorException($message, $severity, $severity, $file, $line);'
)
);
try {
file_get_contents('www.google.com');
}
catch (Exception $e) {
echo $e->getMessage();
}
restore_error_handler();
Seems like a lot of code to catch one little error, but if you're using exceptions throughout your app, you would only need to do this once, way at the top (in an included config file, for instance), and it will convert all your errors to Exceptions throughout.