【发布时间】:2014-06-09 15:41:55
【问题描述】:
我是否遗漏了 php 文档中的某些内容?
我在我的index.php 上设置了一个set_exception_handler 以捕获异常(来自库)并避免未捕获异常的 PHP 致命错误。
当我使用 Apache 运行我的脚本时,我没有问题(捕获异常的函数可以正常工作)。
但是当我尝试使用 PHP cli (php -r 'include "index.php";') 时,我得到了 PHP 致命错误。
有什么想法吗?
-- index.php
set_exception_handler('exception_handler');
throw new Exception("Test exception");
function exception_handler($e) {
echo '-- excemption handler --';
$toLog = '['.date('d/m/Y H:i:s').'] '.$e->getMessage()."\n".$e->getTraceAsString();
var_dump($toLog);
}
【问题讨论】:
-
展示你的代码怎么样?
-
这是一个非常奇怪的问题,它会咬那些偶尔使用
php -r来测试sn-p 的人。看起来像一个错误。
标签: php exception exception-handling command-line-interface