Last active
August 29, 2015 14:02
-
-
Save juji/d3f863d999ae05ffd0c6 to your computer and use it in GitHub Desktop.
PHP - error reporting control
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
error_reporting(E_ALL | E_STRICT); | |
// handle all error | |
ob_start(function($out){ | |
$e = error_get_last(); | |
if(!empty($e)) { | |
return $e['message'] . ' ( ' . $e['file'] . ' [' . $e['line'] . '] )'; | |
} | |
return $out; | |
}); | |
//handle user error | |
set_error_handler(function($no,$str,$file,$line){ | |
print $str . '( '.$file.' ['.$line.'] )'; | |
}); | |
//exception | |
try{ | |
}catch(Exception $e){ | |
print $e->getMessage() . ' -> ' . $e->getFile() . '( '.$e->getLine().' )'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment