Catch does not work and how to disable the exception handler

catch does not work because an exception handler is set using set_exception_handler ()

I need to catch in order to work, so I think I need to somehow disable the exception handler. Things like set_exception_handler (NULL) don't work.

Any ideas on how to remove an 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:

exception found: hello world

Required Conclusion:

should happen: hello world

+3
source share
2 answers

restore_exception_handler , which is associated with manual input for set_exception_handler .

BTW, these exception handlers should come into play only when the exception is not implemented. The catch must always take precedence.


After reading a few comments on the Exceptions page, you will get into this error and this error . They describe exactly what you are experiencing. Exceptions cannot be caught when a custom error handler is defined.

Decision:

Fixed in 5.3 and HEAD, will not be passed back to 5.2.

+5
source

Function restore_exception_handler . However, the handler should be called only when the exception is unhandled. He does not turn off the catches.

0
source

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


All Articles