Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are all uncaught exceptions fatal in PHP?

Tags:

exception

php

While studying for the Zend PHP Exam I came across the following contradicting information:

From the Zend PHP 5.3 Study guide v1a - PDF available here.

enter image description here

The answer:

enter image description here

And information from the php Architect's Zend PHP 5 Certification Study Guide by Davey Shafik ISBN: 0-9738621-4-9 Page 128 enter image description here

Can someone tell me which one is true?

Thanks

like image 705
Rupert Avatar asked Mar 24 '12 08:03

Rupert


People also ask

How does PHP handle uncaught exception?

The primary method of handling exceptions in PHP is the try-catch. In a nutshell, the try-catch is a code block that can be used to deal with thrown exceptions without interrupting program execution. In other words, you can "try" to execute a block of code, and "catch" any PHP exceptions that are thrown.

What are PHP fatal errors?

Fatal Error Fatal errors are ones that crash your program and are classified as critical errors. An undefined function or class in the script is the main reason for this type of error.

What happens with uncaught exceptions?

If an exception is not caught, it is intercepted by a function called the uncaught exception handler. The uncaught exception handler always causes the program to exit but may perform some task before this happens. The default uncaught exception handler logs a message to the console before it exits the program.

In which PHP version fatal errors become exceptions?

Fatal errors or recoverable fatal errors now throw instances of Error in PHP 7 or higher versions. Like any other exceptions, Error objects can be caught using a try/catch block.


1 Answers

From the php manual, please note the unless.

If an exception is not caught, a PHP Fatal Error will be issued with an "Uncaught Exception ..." message, unless a handler has been defined with set_exception_handler().

like image 197
xdazz Avatar answered Sep 28 '22 01:09

xdazz