News Feed
Sections




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

Stefan Priebsch's Blog:
Turning errors into exceptions
April 30, 2008 @ 12:53:35

In a recent blog entry Stefan Priebsch shows how to take an error thrown by your script and turn it into an exception (to make things like catchable fatal errors).

While I would personally prefer an exception to be thrown in the first place, it is pretty easy to convert errors to exceptions in PHP.

His example is pretty simple - you set a custom error handler in your script that pulls in the error information and tosses an exception based on the error number the handler is given. Then you can use the try/catch method to see if your script has tossed an exception of the fatal error type. Nice simple solution to handle an interesting little problem.

0 comments voice your opinion now!
error exception convert try catch fatal errorhandler


blog comments powered by Disqus

Similar Posts

Jani Hartikainen's Blog: The "do X or die()" pattern must die

Lorna Mitchell's Blog: Invalid Protected Resource URL in pecl_oauth

DevShed: Tracking Parsing Errors with the Tidy Library in PHP 5

Mike Purcell's Blog: PHPUnit - Constant Already Defined - -process-isolation

DevShed: Error Handling in PHP - Introducing Exceptions in PHP 5


Community Events





Don't see your event here?
Let us know!


configure series threedevsandamaybe code podcast testing developer wordpress introduction laravel release api unittest language community application library list interview install

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework