Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Catching Errors Before They Catch You
Dec 04, 2002 @ 14:26:25

One thing that even newbies to PHP notice about the language is the way that it handles errors. It's something that I've even seen gurus struggle with, unfortunately, because it's one of the keys to having a successful script that provides useful error messages. This article from the php traveller might just shed some light on a few ways to help you catch and define more of the errors your script throws out.

Catching errors is one of the most important tasks programmers perform. The point of error handling is to correct correctable errors and to fail gracefully where there is no other choice. PHP has a decent mechanism for error handling (see Error Handling and Logging Functions in the manual for more details) but its implementation has one fatal flaw: there exist certain errors that cannot be caught and which result with an immediate termination of the executing program. To me, this is very bad. We can no longer take a corrective action, nor show a meaningful error page to the end user - the user will either see a blank or a partial page.

It's a short little piece, but it has a good suggestion about catching some of the errors that you might get with your scripts. It's much better than the user getting a cryptic error or even, as he mentioned, a partial page. Nothing can ruin your day like a half-parsed page...

Thanks to Ewald for the link.

tagged:

Link:


Trending Topics: