开发时出现异常消息和已发送错误的标头
在我的开发机器中,我将 error_reporting 设置为 E_ALL | E_STRICT
查看我的代码中发生的所有错误消息。 但是当我处理捕获的异常时,例如:
try {
throw new MyException('Exception message.');
} catch (MyException $e) {
// code that handles the exception but without print anything
}
PHP 总是显示错误消息:
MyException: Exception message in file://path/to/failed/file.php
之后 PHP 无法发送新标头。
您是否知道某种方法可以避免通过引发但捕获的 display_errors=On
和 error_reporting=E_ALL |E_STRICT
异常来显示自动生成的 PHP 错误?
In my development machine I have error_reporting set to E_ALL | E_STRICT
to see all the error messages that happen in my code.
But when I deal with caught Exceptions like:
try {
throw new MyException('Exception message.');
} catch (MyException $e) {
// code that handles the exception but without print anything
}
PHP always shows the error message:
MyException: Exception message in file://path/to/failed/file.php
and after that PHP can't send new headers.
Do you know some way to avoid autogenerated PHP errors to be shown by raised, but caught, Exceptions with display_errors=On
and error_reporting=E_ALL |E_STRICT
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置自定义错误处理程序并将错误记录到文件或类似的文件中。有关这方面的信息可以在这里找到: http://php.net/manual /en/function.set-error-handler.php
You can set a custom error handler and have that log errors to a file or something like this. Information on this can be found here: http://php.net/manual/en/function.set-error-handler.php
如果打印消息,将发送标头,句号。如果不需要打印,就不要打印。您可以改为记录它。
If you print the message, headers will be sent, period. If you do not need to print it, don't. You could log it, instead.
好吧,那是我的错。
如果您安装了 xdebug 并且您的 xdebug 配置有
xdebug.show_exception_trace = 1
总是引发异常 xdebug 将转储堆栈跟踪。
Ok, that was my fault.
If you have xdebug installed and if your xdebug configuration has
xdebug.show_exception_trace = 1
allways an exception is raised xdebug will dump the stack trace.