Exceptions generated in the PHP code can be
throw
Statement is thrown, and is
catch
Statement capture. Code that requires exception handling must be placed in the
try
Within the code block, each
try
At least one of the corresponding
catch
。 When an exception is thrown, the code behind the block of code will not proceed, and PHP will attempt to find the first one to match it.
catch
。 Of course, PHP allows you to
catch
The code block is thrown in again
throw
Abnormal. If an exception is not captured and is not used
set_exception_handler()
, PHP will produce a serious error.
Here is an example of the use of exceptions.
'; echo inverse(0) . '
';} catch(Exception $e) { echo 'Caught exception: ' . $e->getMessage() . '
';}echo 'hello';
There is also an example of an exception nesting.
getMessage()); } }}$foo = new Test;$foo->testing();
Users can use custom exception handling classes to extend PHP's built-in exception handling classes.
(End of full text)
The above describes the exception handling-PHP manual notes, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.