views:

60

answers:

1

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?

A: 

the posted code, called directly works as you expect.

Cesar
yeah, but why could it possibly not be working in my setup?
neoneye
did you tried to run it directly ? same result ?
Cesar
yeah, when I run this code I get that PHP Fatal error I posted. I named the file index.php and opened via Firefox. So I guess our setups must be different, but what could be causing it?
neoneye