Hindi Songs

Wednesday, July 8, 2009

Example explained:

The code above throws an exception and catches it:

1. The checkNum() function is created. It checks if a number is greater than 1. If it is, an exception is thrown

2. The checkNum() function is called in a "try" block

3. The exception within the checkNum() function is thrown

4. The "catch" block retrives the exception and creates an object ($e) containing the exception information

5. The error message from the exception is echoed by calling $e->getMessage() from the exception object

However, one way to get around the "every throw must have a catch" rule is to set a top level exception handler to handle errors that slip through.