当我扩展Exception类时:
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问题吗? 感谢。
答案 0 :(得分:3)
这是一个xdebug选项。在您的php.ini中,您有xdebug.scream=1
要禁用它,请将其设置为xdebug.scream=0
Scream会覆盖@
“闭嘴”操作符,因此您必须将其关闭以阻止此操作发生。不要忘记重新启动服务器以使更改生效。
答案 1 :(得分:0)
您必须使用try-catch
块捕获异常。否则,它将报告未被捕获的异常。
例如:
try {
methodThatCanThrowAnException(); // used since I don't know the method you are trying to call
}
catch (CustomException $e) {
echo $e->getMessage();
}