何时捕获 java.lang.Error?

When to catch java.lang.Error?(何时捕获 java.lang.Error?)

本文介绍了何时捕获 java.lang.Error?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下应该在应用程序上捕获java.lang.Error?

In what situations should one catch java.lang.Error on an application?

推荐答案

一般情况下,从不.

但是,有时您需要捕获特定错误.

However, sometimes you need to catch specific errors.

如果您正在编写类似于框架的代码(加载第 3 方类),最好捕获 LinkageError(未找到类定义、不满意的链接、不兼容的类更改).

If you're writing framework-ish code (loading 3rd party classes), it might be wise to catch LinkageError (no class def found, unsatisfied link, incompatible class change).

我还看到一些愚蠢的 3rd-party 代码抛出 Error 的子类,所以你也必须处理这些.

I've also seen some stupid 3rd-party code throwing subclasses of Error, so you'll have to handle those as well.

顺便说一句,我不确定是否无法从 OutOfMemoryError 中恢复.

By the way, I'm not sure it isn't possible to recover from OutOfMemoryError.

这篇关于何时捕获 java.lang.Error?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:何时捕获 java.lang.Error?

基础教程推荐