TRY-CATCH statement
To further process an exception, we need to use the try-catch statement - including the TRY statement and at least one CATCH statement. Any code that calls that may throw an exception should use the TRY statement. The Catch statement is used to handle an exception that may be thrown. The following shows how we handle the exceptions thrown by getcommandObject ():
Index_php5.php second half
php // php 5 try {$ mgr = new commandmanager (); $ cmd = $ mgr-> getcommandObject ('realcommand'); $ cmd-> execute ();} catch (Exception $ E) {Print $ E -> GetMessage (); exit ();}?>
It can be seen that we can avoid the value returned by the error mark by combining the use of the THROW keyword and the TRY-CATCH statement. Because "exception" itself is a type of PHP built with any other object, it will not be confused.
If you throw an exception, the script in the TRY sentence will stop execution, then turn to the script in the execution of the CATCH statement.
If the exception throws, it will generate a Fatal Error if it is not captured.