O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

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

3.6. Exceptions

When errors occur, PHP sends text to the browser. Some errors halt execution. For the error conditions that don't halt execution, you may trap them with a function you register with set_error_handler. See Chapter 15 for a discussion of this function. You can even generate your own errors with trigger_error, discussed in Chapter 9.

Alternatively, you may use exceptions. Figure 3.7 shows the form. Exceptions are object-oriented error conditions. They occur within the context of a try statement. To initiate an exception, you make a throw statement. Control then passes to a catch block, which receives a copy of the thrown exception. Add a catch block for each type of exception you wish to catch, or simply use PHP's built-in Exception ...

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