O'Reilly logo

PHP 7 Quick Scripting Reference, Second Edition by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_30

30. Exception Handling

Mikael Olsson

(1)Hammarland, Finland

PHP 5 introduced exceptions, a built-in mechanism for handling program failures within the context in which they occur. Unlike errors, which generally need to be fixed by the developer, exceptions are handled by the script. They represent an irregular run-time situation that should have been expected as a possibility and which the script should be able to handle on its own.

Try-catch Statement

To handle an exception, it must be caught using a try-catch statement . This statement consists of a try block containing the code that may cause the exception, and one or more catch clauses.

try{  $div ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required