Catch does not work

I am puzzled. What can cause a "catch" to not work and how to fix it?

<?php try { throw new Exception('BOOM'); error_log("should not happen"); } catch(Exception $e) { error_log("should happen: " . $e->getMessage()); } ?> 

Actual output

 [27-Apr-2010 09:43:24] PHP Fatal error: Uncaught exception 'Exception' with message 'BOOM' in /mycode/exception_problem/index.php:4 Stack trace: #0 {main} thrown in /mycode/exception_problem/index.php on line 4 

Desired output

 should happen: BOOM 

PHP version 5.2.3

In php_info () I don't see that exceptions can be disabled.

I tried with "restore_exception_handler ();" but this does not work the catch block.

I also tried using "set_exception_handler (NULL)"; but this does not work the catch block.


How to get the desired result?

+4
source share
1 answer

published code called directly works as you expect.

0
source

Source: https://habr.com/ru/post/1308116/


All Articles