【发布时间】:2013-10-01 23:00:25
【问题描述】:
我选择了这个标题,因为我遇到了与此处所述完全相同的问题: PHP exceptions thrown in error handler are not caught by exception handler
作者接受了说他显然做错了什么的答案。 我的错误和异常处理程序在过去两年中运行良好,但现在我面临着完全相同的问题。 我做了代码更新和服务器更新(Plesk 11.5 运行,PHP 版本应该是相同的,是 5.3.2)。我检查了我的代码是否有错误,但测试表明这不是问题所在:
我写了以下测试文件:
function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
throw new Exception("this was an error");
}
function exceptionHandler($e) {
echo 'exceptionHandler';
}
set_error_handler('errorHandler');
set_exception_handler('exceptionHandler');
// test one:
throw new Exception(); // outputs "exceptionHandler"
// test two - uncomment the first test of course!
$test->blabla();
第二个测试也应该输出“exceptionHandler”,但它没有! 输出为“致命错误:在第 0 行......./exeptiontest.php 中的非对象上调用成员函数 blabla()”
这个问题现在让我发疯了。这里有什么建议吗?任何导致此问题的 PHP 设置?
【问题讨论】:
-
你不能用
set_error_handler()处理致命错误 -
@SamDufel 是的,我愿意。问题是错误处理程序中抛出的异常没有被异常处理程序捕获..
标签: php exception exception-handling plesk