O'Reilly logo

Sams Teach Yourself PHP in 24 Hours, Third Edition by Matt Zandstra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing Error Conditions with Exceptions

Although it was possible to set a custom error handler in PHP 4, most scripts prior to PHP 5 made do with relatively crude error handling. Methods that ran into trouble would generally choose between using die() to end script execution completely or returning a flag value such as false or -1.

PHP 5 introduces exceptions, allowing methods to hand responsibility back to client code when particular errors are encountered.

An exception is an object that can be automatically populated with information about the error that has occurred and its script context. You must instantiate Exception objects yourself with the new keyword just as you would with any object. Once you have an Exception object, you can literally ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required