69 篇文章 0 订阅

# 应该catch什么

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.
Java Lanuage Spec 7 中也提到：Error继承自Throwable而不是继承自Exception，是为了方便程序可以使用 “catch (Exception)“来捕捉异常而不会把Error也捕捉在内，因为Exception发生后可以进行一些恢复工作的，但是Error发生后一般是不可恢复的。
The class Error is a separate subclass ofThrowable, distinct from Exception in the class
hierarchy, to allow programs to use the idiom “} catch (Exception e) { " (§11.2.3)
to catch all exceptions from which recovery may be possible without catching errors from which recovery is typically not possible.

# Error可以catch吗？ 可以catch了后做些其他处理吗？

Error是可以catch的，而且也可以向常规Exception一样被处理，而且就算不捕捉的话也只是导致当前线程挂掉，其他线程还是可以正常运行，如果有需要的话捕捉Error之后也可以做些其他处理。但是Error是一种系统内部的错误，这种错误不像Exception一样是可能是程序和业务上的错误是可以恢复的。

http://blog.csdn.net/hguisu/article/details/6155636
http://www.cnblogs.com/dolphin0520/p/3769804.html
http://doc.okbase.net/foxty/archive/120046.html

• 15
点赞
• 19
收藏
• 1
评论
05-09 1万+
09-08 432
10-09 409
11-15 378
03-20 470
10-11 123
09-06 2万+
04-12 70
09-04 5035

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助