Customizing PHP exceptions


show more Customizing PHP exceptions provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP show less
please wait ...

Customizing PHP exceptions

In the previous segment, we threw an exception, because of an unknown address ID, but didn't catch it, which resulted in a fatal error. Let's make the demo more resilient, and deal with this unfortunate circumstance by wrapping the load attempt in a try block. I'm going to switch the demo. try. A catch block must follow the try block. The catch block doesn't have to be immediately afterwards, and other code can execute in between, but it's generally best practice to have the catch as close to the try as possible.

To catch an exception, use the catch keyword, followed by parentheses containing the class of the exception you wish to catch, which is the same as what was thrown, and a variable to put the thrown exception in, if any. Let's catch that exception. catch parentheses Exception $e. Once caught, you can optionally take further action. In this case, rendering the message that was included in the thrown exception is sufficient. Often, exception messages are int...

Customizing PHP exceptions
Video duration: 4m 23s 1h 57m Intermediate Updated Apr 10, 2013

Viewers:

Customizing PHP exceptions provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...