Catching errors and Warnings
Below is a standard for catching errors. This would not work for warnings. That code is at the bottom.
1 2 3 4 5 6 7 8 9 10 |
try { print "this is our try block n"; throw new Exception(); } catch (Exception $e) { print "something went wrong, caught yah! n"; } finally { print "this part is always executed n"; } |
How to catch warnings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context) { throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line ); }, E_WARNING); try { // any code that may have a warning } //restore the previous error handler restore_error_handler(); |