News Feed
Sections




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

Jani Hartikainen's Blog:
How to use built-in SPL exception classes for better error handling
May 09, 2011 @ 08:47:12

On his blog today Jani Hartikainen looks at how you can use the SPL exception types to allow for better overall error handling in your application. Things like BadMethodCallException and OutOfBoundsException make the errors much more descriptive.

Since PHP 5, there has been a bundle of built-in exceptions - the "SPL exceptions" - in PHP. However, the documentation for these classes is quite lacking in examples, and it can be difficult to understand when you should be using them. The short answer is always.

The list of exception types he recommends include:

  • BadMethodCallException
  • DomainException
  • LengthException
  • OutOfRangeException
  • UnexpectedValueException

For each he gives an example usage of it, sometimes including a bit of code to illustrate.

0 comments voice your opinion now!
spl standardphplibrary exception handling classes types


blog comments powered by Disqus

Similar Posts

Kenny Meyers' Blog: How CodeIgniter Works (Video from EECI 2010)

DevShed: Enforcing Object Types in PHP - Using the PHP5 instanceof Operator

PHPMaster.com: Data Structures for PHP Devs: Heaps

Jacob Santos's Blog: Don't Advocate Inner Classes

Zend Developer Zone: The ZendCon Sessions Episode 24: Elegant Ways of Handling PHP Errors and Except


Community Events

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


php7 performance symfony2 laravel opinion introduction part2 language configure api podcast framework interview community example series conference application voicesoftheelephpant release

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