問題描述
我如何處理解析 &使用自定義錯誤處理程序的致命錯誤?
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
,我們應該看看handling的定義:對我來說,處理錯誤意味著捕捉錯誤并以對用戶和底層數據(數據庫、文件、網絡服務等)很好"的方式做出反應.
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:自定義錯誤處理程序 - 處理解析 &致命錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!