代码之家  ›  专栏  ›  技术社区  ›  neoneye

接球不起作用

  •  4
  • neoneye  · 技术社区  · 14 年前

    我很困惑。什么可能导致“catch”不起作用?我该如何修复它?

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

    实际产量

    [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
    

    期望输出

    should happen: BOOM
    

    php版本5.2.3

    在php_info()中,我看不到任何可能被禁用的异常。

    我试过使用“restore_exception_handler();”但这并不能使catch块工作。

    我也尝试过使用“set_exception_handler(null);”,但这两种方法都不能使catch块工作。


    如何获得所需的输出?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Cesar    14 年前

    所发布的代码,直接调用,正如您所期望的那样工作。