何时捕获java.lang.Error? [英] When to catch java.lang.Error?
问题描述
在应用程序中应该捕获 java.lang.Error
的情况
In what situations should one catch java.lang.Error
on an application?
推荐答案
一般来说,永远不会。
但是,有时您需要捕获特定的错误。
Generally, never. However, sometimes you need to catch specific Errors.
如果您正在编写framework-ish代码(加载第三方类),那么这可能是明智之举捕获LinkageErrors(没有找到类def,不满足的链接,不兼容的类更改)。
我还看到一些愚蠢的第三方代码抛出了错误的子体,所以你也必须处理这些。
If you're writing framework-ish code (loading 3rd party classes), it might be wise to catch LinkageErrors (no class def found, unsatisfied link, incompatible class change). I've also seen some stupid 3rd-party code throwing sublcasses of Errors, so you'll have to handle these either.
顺便说一下,我'不确定不可能从OutOfMemory恢复。
By the way, I'm not sure it isn't possible to recover from OutOfMemory.
这篇关于何时捕获java.lang.Error?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!