PHP:自定义错误处理程序 - 处理解析和致命错误 [英] PHP : Custom error handler - handling parse & fatal errors

查看:86
本文介绍了PHP:自定义错误处理程序 - 处理解析和致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何处理 parse & 致命错误使用自定义错误处理程序?

How can i handle parse & fatal errors using a custom error handler?

推荐答案

简单答案:你不行请参阅手册

Simple Answer: You can't. See the manual:


以下错误类型不能用
处理
E_ERROR,E_PARSE,E_CORE_ERROR,
E_CORE_WARNING,E_COMPILE_ERROR,
E_COMPILE_WARNING,大部分
E_STRICT在调用
set_error_handler()的文件中引发。

The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

对于所有其他错误,您可以使用 set_error_handler()

For every other error, you can use set_error_handler()

编辑:

由于似乎有一些关于这个话题的讨论,关于使用 register_shutdown_function ,我们应该看看处理的定义:To我,处理一个错误意味着捕获错误并以对用户底层数据(数据库,文件,Web服务等)好的方式进行反应。

Since it seems, that there are some discussions on this topic, with regards to using register_shutdown_function, we should take a look at the definition of handling: To me, handling an error means catching the error and reacting in a way that is "nice" for the user and the underlying data (databases, files, web services, etc.).

使用 register_shutdown_function 您无法处理在代码中被调用的错误,意味着代码将仍然停止工作在发生错误的点。但是,您可以向用户显示一条错误消息而不是白页,但是您可能无法在代码失败之前回滚任何代码。

Using register_shutdown_function you cannot handle an error from within the code where it was called, meaning the code would still stop working at the point where the error occurs. You can, however, present the user with an error message instead of a white page, but you cannot, for example, roll back anything that your code did prior to failing.

这篇关于PHP:自定义错误处理程序 - 处理解析和致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆