Exception Handling – PHP Tutorial



This tutorial is part 1/2 about exception handling in PHP. The video will teach you how to throw, try, and catch exceptions, as well as how to create your own custom exception types. The reason you’d want a custom exception type is so you can catch it individually, and attempt to handle it accordingly. The reason for throwing exceptions is to prevent the program to continue to execute if a certain condition is not met. For example, there’s no reason to continue execution of a game if the graphics card doesn’t support your 3D rendering engine. How can the player use your program (play your game), if he or she can’t see anything?!

PHP 5.5 introduced the long awaited finally clause, which executes after the try catch block, whether or not an exception is thrown in the process. This is very handy for when you need to perform a given action in either case, such as closing a file, or a connection, or logging whatever data into a log file.

Copyright (c) 2013 Rodrigo Silveira http://www.easylearntutorial.com

source

Reply


Build A Site Info