2013-07-19 31 views
2

一个例外是在我关机功能抛出抓到一个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 
}); 

Live run.

运行上面的代码给出:

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没有捕获异常抛出?

回答

0

因为它超出范围...

http://www.php.net/manual/en/function.register-shutdown-function.php

Registers a callback to be executed after script execution finishes or exit() is called.

那一定是你处理剥离下来作为脚本的执行已经完成,并在事实上关闭。

+0

但是,您声称的文档根本没有被文档提及。 http://php.net/set_exception_handler的文档没有声明它超出了上述用例的范围。 – Pacerier

相关问题