捕获不起作用 [英] Catch isn't working

查看:75
本文介绍了捕获不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑。是什么导致捕获不起作用以及如何解决?

<?php

try {
    throw new Exception('BOOM');
    error_log("should not happen");
} catch(Exception $e) {
    error_log("should happen: " . $e->getMessage());
}

?>



实际输出



Actual output

[27-Apr-2010 09:43:24] PHP Fatal error:  Uncaught exception 'Exception' with message 'BOOM' in /mycode/exception_problem/index.php:4
Stack trace:
#0 {main}
  thrown in /mycode/exception_problem/index.php on line 4



所需的输出



Desired output

should happen: BOOM






PHP版本5.2.3


PHP version 5.2.3

在php_info()中

In php_info() I don't see anywhere exceptions could have been disabled.

我尝试使用 restore_exception_handler();

I have tried with "restore_exception_handler();" but that doesn't make the catch block working.

我也尝试过使用 set_exception_handler(NULL);。

I have also tried with "set_exception_handler(NULL);" but that neither make the catch block working.

如何获得所需的输出?

推荐答案

直接调用已发布的代码即可。

the posted code, called directly works as you expect.

这篇关于捕获不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆