- A new object oriented way of dealing with errors came with PHP 5. Exceptions are important and provides a better control over error handling.
- Lets explain three new keywords related to exceptions:
- Try - A function using an exception should be in a "try" block. If the exception does not trigger, the code will continue as normal. However if the exception triggers, an exception is "thrown".
- Throw - This is how you trigger an exception. Each "throw" must have at least one "catch".
- Catch - - A "catch" block retrieves an exception and creates an object containing the exception information.
- When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block. If an exception is not caught, a PHP Fatal Error will be issued with an "Uncaught Exception” .
- You can define your own custom exception handler. Use following function to set a user-defined exception handler function.
-
1
string set_exception_handler ( callback $exception_handler )
-
- PHP Sessions
- PHP Error
- PHP Filter
- MySQL Introduction