Catch isn't working

Posted by neoneye on Stack Overflow See other posts from Stack Overflow or by neoneye
Published on 2010-04-27T08:00:13Z Indexed on 2010/04/27 8:03 UTC
Read the original article Hit count: 441

Filed under:
|
|

I'm baffled. What could be causing 'catch' not to be working and how do I 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 anywhere exceptions could have been disabled.

I have tried with "restore_exception_handler();" but that doesn't make the catch block working.

I have also tried with "set_exception_handler(NULL);" but that neither make the catch block working.


How do I get the desired output?

© Stack Overflow or respective owner

Related posts about php

Related posts about exceptions