By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,491 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,491 IT Pros & Developers. It's quick & easy.

Trapping Errors

P: n/a
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?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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>
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.