ExamplesExample #1 Throwing an Exception The above example will output: 0.2 Caught exception: Division by zero. Hello World Example #2 Exception handling with a The above example will output: 0.2 First finally. Caught exception: Division by zero. Second finally. Hello World Example #3 Interaction between the The above example will output: finally Example #4 Nested Exception The above example will output: string(4) "foo!" Example #5 Multi catch exception handling The above example will output: string(11) "MyException" Example #6 Omitting the caught variable Only permitted in PHP 8.0.0 and later. The above example will output: A SpecificException was thrown, but we don't care about the details. Example #7 Throw as an expression Only permitted in PHP 8.0.0 and later. The above example will output: It did not work Example #8 Exception in try and in finally The above example will output: string(5) "First" string(6) "Second" string(5) "Third" string(6) "Fourth" |