On 20 Jan 2004 09:38:09 -0800,
ju******@mailcity.com (Spike) wrote:
Is there a clean way to trap errors in PHP?
In Perl there is eval { <code> } and a special variable that can be
checked to see if the execution of the code was successful or not, and
thus a clean way to trap the error without it killing the entire
script.
Is there something similar in PHP?
There is eval() in PHP, but it's not as clean as in Perl, as PHP's exception
handling's not the same; die() doesn't set a variable like $@ in Perl. It's
also icky as you have to pass it a string, it's not a language construct around
a code block.
You could use the PHP error handling functions to set up an error handler of
your own to catch all errors, look up set_error_handler().
--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>