Exception Handling - PHP Manual Notes

WBOY
Release: 2016-08-08 09:28:49
Original
958 people have browsed it

Exceptions generated in PHP code can be thrown by thethrowstatement and captured by thecatchstatement. Code that requires exception handling must be placed within thetrycode block, and eachtrymust have at least one correspondingcatch. When an exception is thrown, the code following the code block will not continue to execute. At this time, PHP will try to find the first matchingcatch. Of course, PHP allowsthrowexceptions to be thrown again within acatchcode block. If an exception is not caught and handled accordingly usingset_exception_handler(), PHP will generate a fatal error.

Here is an example of exception usage.

'; echo inverse(0) . '
'; } catch(Exception $e) { echo 'Caught exception: ' . $e->getMessage() . '
'; } echo 'hello';
Copy after login

There is also an example of exception nesting.

getMessage()); } } } $foo = new Test; $foo->testing();
Copy after login

Users can extend PHP's built-in exception handling classes with custom exception handling classes.

(Full text ends)

The above introduces the exception handling - PHP manual notes, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!