catch不起作用是因为使用set_exception_handler()安装了异常处理程序。
我需要让“catch”起作用,所以我猜我需要以某种方式取消异常处理程序。像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());
}
实际输出:
捕获异常: hello world
期望输出:
应该发生: hello world