O'Reilly logo

PHP and MySQL Web Development, Third Edition by Laura Thomson, Luke Welling

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

Chapter 7. Exception Handling

In this chapter, we explain the concept of exception handling and the way it is implemented in PHP. Exceptions are a new and important feature in PHP5. They provide a unified mechanism for handling errors in an extensible, maintainable, and object-oriented way.

Key topics covered in this chapter include

  • Exception handling concepts

  • Exception control structures: try...throw...catch

  • The Exception class

  • User-defined exceptions

  • Exceptions in Bob's Auto Parts

  • Exceptions and PHP's other error handling mechanisms

Exception Handling Concepts

The basic idea of exception handling is that code is executed inside what is called a try block. That's a section of code that looks like this:

try
{
  // code goes here
}

If something goes wrong ...

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