Skip to content

Instantly share code, notes, and snippets.

@davidraedev
Created September 9, 2018 00:07
Show Gist options
  • Save davidraedev/7973d909f224266807c692e8afc5e872 to your computer and use it in GitHub Desktop.
Save davidraedev/7973d909f224266807c692e8afc5e872 to your computer and use it in GitHub Desktop.
php file_get_contents catch error
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 $error ) {
echo $error->getMessage();
}
restore_error_handler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment