# Java的Error与Exception

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.
A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur. That is, Error and its subclasses are regarded as unchecked exceptions for the purposes of compile-time checking of exceptions.

Error 是 Throwable 的子类，用于指示合理的应用程序不应该试图捕获的严重问题。大多数这样的错误都是异常条件。虽然 ThreadDeath 错误是一个“正规”的条件，但它也是 Error 的子类，因为大多数应用程序都不应该试图捕获它。

Error的设计初衷就是为了表示那些程序自身无法处理的严重错误的，譬如OutOfMemory，只有当内存不足，且JVM无法通过GC释放内存，不得已才抛出的错误。既然JVM已经无法回收空间了，我们捕获了又能干什么呢？不能释放的对象说明我们正在使用，只有通过优化代码逻辑或者增大JVM内存来解决了。

posted @ 2020-04-23 14:54  。淑女范erり  阅读(139)  评论(0编辑  收藏  举报