neo*_*eye 3 php exception try-catch
catch无效,因为使用set_exception_handler()安装了异常处理程序
我需要"捕获"才能工作,所以我想我需要以某种方式取消设置异常处理程序.诸如set_exception_handler(NULL)之类的东西不起作用.
任何想法如何取消设置异常处理程序?
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());
}
Run Code Online (Sandbox Code Playgroud)
抓住异常:你好世界
应该发生:你好世界
restore_exception_handler,从手册输入链接set_exception_handler.
顺便说一句,这些异常处理程序只有在未被捕获的情况下才能发挥作用.一个catch块应始终优先.
阅读Exceptions页面上的注释中的一点点可以看到这个bug和这个bug.它们准确描述了您的体验,定义了自定义错误处理程序时无法捕获异常.
解:
固定在5.3和HEAD中,不会被反向移植到5.2.