Catch not working and how to unset the exception handler

Posted by neoneye on Stack Overflow See other posts from Stack Overflow or by neoneye
Published on 2010-04-26T14:42:32Z Indexed on 2010/04/27 8:13 UTC
Read the original article Hit count: 354

Filed under:
|
|

catch is not working because there is installed an exception handler using set_exception_handler()

I need "catch" to work, so I guess I need to unset the exception handler somehow. Things such as set_exception_handler(NULL) isn't working.

Any ideas how to unset the exception handler?

function my_exception_handler($exception) {
    error_log("caught exception: " . $exception->getMessage() );
}

set_exception_handler("my_exception_handler");

// QUESTION: how does on unset it ?
//set_exception_handler(NULL);

try {
    throw new Exception('hello world');
    error_log("should not happen");
} catch(Exception $e) {
    error_log("should happen: " . $e->getMessage());
}

Actual output:

caught exception: hello world

Desired output:

should happen: hello world

© Stack Overflow or respective owner

Related posts about php

Related posts about exception