Chapter 30. Handing Exceptions with PHP
Until now, programmers have been very creative in figuring out how to deal with error cases within PHP, whether setting and printing error strings or using and abusing the limited error reporting system. Despite its many useful features, PHP has not contained a good system for comprehensively dealing with errors. Fortunately, this changed with PHP5.
Error Handling in PHP
If you are familiar with structured programming languages, such as C and Java, you have probably grown accustomed to the various built-in objects that allow you to handle errors and exceptions. If so, you'll be happy to note that PHP5 now includes, for the first time, an exception-handling object, and that the syntax is very similar to existing languages like Java. In fact, once you learn a bit of syntax you can begin handling errors and exceptions much as you have been with other object-oriented languages.
However, if you have been primarily using PHP, and are unfamiliar with other languages, the idea of exception handling may be new to you. Exception handling is a powerful tool that you will come to appreciate once you understand the concept and put it to good use in your code. This new built-in function will enable you to debug error conditions, recover from unexpected situations, and present a clean interface to your end users ...
Get PHP6 and MySQL® 6 Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.