如何判断错误是否被@错误控制运算符抑制? [英] How to tell if an error was suppressed by the @ error control operator?
问题描述
我正在使用的第三方库在其代码中使用@错误抑制运算符,这会通过@导致抑制错误,但由于我使用的是自定义错误处理程序(set_error_handler())
,因此仍会导致错误输出.
A 3rd party library I'm using uses the @ error suppression operator in its codes which causes suppressed errors via @ still cause an error output because I am using a custom error handler (set_error_handler())
.
在此页面中,它说
如果您已使用set_error_handler()设置了一个自定义错误处理函数,则该函数仍将被调用,但此自定义错误处理函数可以(并且应该)调用error_reporting(),该函数在触发该错误的调用之前将返回0.通过@.
If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @.
但是目前还不清楚我如何才能准确地捕获@之前的错误.
However it is unclear how exactly can I catch the errors that was preceded by an @.
我的问题是如何捕获通过@抑制的错误?
My question is how can I catch errors that was suppressed via @?
推荐答案
如前所述:您的错误处理程序仍将照常调用,但是如果产生了错误,则在错误处理程序内部调用error_reporting()
会产生0
在@
的上下文中.因此,您的错误处理程序应考虑到这一点并采取相应措施.
As it says: your error handler will still be invoked as usual, but calling error_reporting()
inside your error handler will yield 0
if the error was produced in the context of an @
. So your error handler should take that into account and act accordingly.
这篇关于如何判断错误是否被@错误控制运算符抑制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!