一个例外是在我关机功能抛出不抓到一个try/catch块内,例如:为什么set_exception_handler(func)不能捕获异常?
<?php
set_exception_handler(function($e){
echo "exception handled"; // not echoed
});
register_shutdown_function(function(){
throw new Exception("test"); // this should be caught by the exception handler above, but it doesn't
});
运行上面的代码给出:
Fatal error: Uncaught exception 'Exception' with message 'test'
然而PHP Manual声称:
set_exception_handler sets the default exception handler if an exception is not caught within a try/catch block. Execution will stop after the exception_handler is called.
为什么exception_handler
没有捕获异常抛出?
但是,您声称的文档根本没有被文档提及。 http://php.net/set_exception_handler的文档没有声明它超出了上述用例的范围。 – Pacerier