PHP5.2.6中无法在exception_handler函数中抛出异常
在PHP bugs列表中也找到这个bug,但是似乎没有被处理,bug提出的时间是2005年,不知道新版本的有没有解决。
PHP:5.2.6
OS: Mac OS Leopard 10.5.7
Server: Apache 2.2
这个代码就有问题:
function e_handler($e)
{
throw new Exception();
}
set_exception_handler(‘e_handler’);
throw new Exception();
这将会导致
Fatal error: Exception thrown without a stack frame in Unknown on line 0
Update: 这应该属于设计问题,如果在exception_handler()函数中可以跑出异常,则这个异常优惠调用exception_handler(),这样下去就会出现死循环,这就是为什么程序会出错的原因吧。
通过try catch来处理的话就没有问题。。
function e_handler($e)
{
try
{
throw new Exception();
}
catch (Exception $e)
{
echo “catched…”;
}
}
set_exception_handler(‘e_handler’);
throw new Exception();


















