Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unhandled errors in php

How can I know during runtime that my code threw a Warning?

example

try {
    echo (25/0);
} catch (exception $exc) {
    echo "exception catched";
}

throws a "Warning: Division by zero" error that i can not handle on my code.

like image 742
lexus Avatar asked Mar 27 '10 11:03

lexus


1 Answers

You're looking for the function set_error_handler(). Check out the sample code in the manual.

Make sure that you don't only suppress the error warnings, but instead silently redirect them to a log file or something similar. (This helps you track down bugs)

like image 159
svens Avatar answered Nov 13 '22 23:11

svens