1

当我扩展一个异常类时:

CustomException extends Exception(){}

throw new CustomException("Houston we have a problem",1);

错误:

SCREAM: Error suppression ignored for
Uncaught exception 'CustomException' with message 'Houston we have a problem' in C:\wamp\www\index.php on line 5
CustomException: Houston we have a problem in C:\wamp\www\index on line 5

我只想要 CustomException 消息:

CustomException: Houston we have a problem in C:\wamp\www\index on line 5

这可能吗?这是一个xdebug问题吗?谢谢。

4

2 回答 2

3

这是一个 xdebug 选项。在您的 php.ini 中,您必须xdebug.scream=1禁用它,将其设置为xdebug.scream=0

Scream 会覆盖@“闭嘴”运算符,因此您必须将其关闭以阻止这种情况发生。不要忘记重新启动服务器以使更改生效。

于 2013-02-16T03:30:10.150 回答
0

您必须使用try-catch块捕获异常。否则它将报告未捕获的异常。

例如:

try {
  methodThatCanThrowAnException(); // used since I don't know the method you are trying to call
}
catch (CustomException $e) {
  echo $e->getMessage();
}
于 2013-02-16T03:27:18.633 回答