简体   繁体   English

PHP异常显示在try和catch块中

[英]PHP Exception shows anyway in try & catch block

I have a very strange situation: code shown below should print no error in PHP. 我有一个非常奇怪的情况:下面显示的代码应该在PHP中不打印错误。

try {
    throw new Exception('foo');
} catch(Exception $e) {
    // here could be some custom functions to handle errors
    die();
}

On my computer it prints 在我的计算机上打印

( ! ) SCREAM: Error suppression ignored for
( ! ) Exception: foo. in D:\wamp\www\index.php on line 4

Why? 为什么? Which php ini option does that? 哪个php ini选项呢?

The Scream extension is an extension aimed at developers, so that they get to see error messages from their code even when they would normally be suppressed. Scream扩展是针对开发人员的扩展,因此即使通常会被抑制,他们也可以从代码中看到错误消息。

xDebug is another developer extension that also includes the same functionality. xDebug是另一个开发人员扩展,也包含相同的功能。

If you have either of these extensions, the Scream feature can be disabled in your PHP config. 如果您具有这些扩展中的任何一个,则可以在PHP配置中禁用Scream功能。

But neither of those extensions should be in use on a production system -- they are intended for use on a developer's system only. 但这些扩展都不应该在生产系统上使用 - 它们仅用于开发人员的系统。 If it's on your live site, then the extension should be disabled entirely. 如果它在您的实时站点上,则应完全禁用该扩展。

http://www.php.net/manual/en/scream.examples-simple.php http://www.php.net/manual/en/scream.examples-simple.php

Usually, scream is used to override the silence operator (@), but if its doing it for try catch, as well...you can try to use an in-line ini_set to turn it off and see if that fixes it. 通常,尖叫用于覆盖静默运算符(@),但如果也将其用作try catch,则...也可以尝试使用内联ini_set将其关闭,看看是否可以解决该问题。

Thank you all for answers. 谢谢大家的答案。 Yes, the problem was xdebug, to be more accurate: xdebug.show_exception_trace option., which was turned to on . 是的,问题是Xdebug的,更准确: xdebug.show_exception_trace选项,这是转向。 on

As we read from xdebug documentation : 正如我们从xdebug文档中看到的:

xdebug.show_exception_trace xdebug.show_exception_trace
Type: integer, Default value: 0 类型:整数,默认值:0
When this setting is set to 1, Xdebug will show a stack trace whenever an exception is raised - even if this exception is actually caught. 当此设置设置为1时,Xdebug将在引发异常时显示堆栈跟踪 - 即使实际捕获到此异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM