PHP5: Why is try/catch failing?

喜夏-厌秋 提交于 2019-12-11 07:08:22

问题


On my XAMPP/Win XP build, PHP5.2.3 fails to catch any exceptions. None of the examples work, and this:

try {
    throw new Exception('Fail');
} catch (Exception $e) {
    echo 'Succeed';
}

...results in:

Fatal error: Uncaught exception 'Exception' with message 'Fail' in M:\path\to\test.php:4 Stack trace: #0 {main} thrown in M:\path\to\test.php on line 4

All of PHP's error settings seem standard. Server is Apache/2.2.4


回答1:


This depends on eAccelerator's build in XAMPP. At one point, it had trouble optimizing try/catch statements and just ignored them.

The problem was in 0.9.5. XAMPP currently is bundled with eAccelerator 0.9.5.3, although it is disabled by default. So this might not be your issue.

According to the ChangeLog, XAMPP hasn't used PHP 5.2.3 and Apache 2.2.4 in a LONG time, which is also around the time of the eAccelerator bug. I recommend checking your eAccelerator version and possibly upgrading XAMPP.




回答2:


I get "Succeed" as output running your script, both standalone on command line and via apache on a webserver as well as in XAMPPLITE. Dunno what's different from your setup



来源:https://stackoverflow.com/questions/692144/php5-why-is-try-catch-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!