PHP AdvancedLesson 42Free preview
PHP Exceptions
This lesson is part of PHP · All levels
Summary
Exception is a PHP mechanism for handling errors when a program is running in a structured manner. You can block the risky code with try, catch the problem with catch, and guarantee clearance with finally. With the exception of failure, failure can be handled without making the program immediately stop completely.
Key points
- Exception thrown with throw new
- Block try to host code that risks error
- Block catch catches and handles the exception thrown
- The block finally always runs, whether there are exceptions or not.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.