Java Exception

  先贴上一段Exception源码注释

 1 /**
 2  * The class {@code Exception} and its subclasses are a form of
 3  * {@code Throwable} that indicates conditions that a reasonable
 4  * application might want to catch.
 5  *
 6  * <p>The class {@code Exception} and any subclasses that are not also
 7  * subclasses of {@link RuntimeException} are <em>checked
 8  * exceptions</em>.  Checked exceptions need to be declared in a
 9  * method or constructor's {@code throws} clause if they can be thrown
10  * by the execution of the method or constructor and propagate outside
11  * the method or constructor boundary.
12  *
13  * @author  Frank Yellin
14  * @see     java.lang.Error
15  * @jls 11.2 Compile-Time Checking of Exceptions
16  * @since   JDK1.0
17  */

  第一段能看出Exception与Error的不同,Exception是一个系统想要捕获的东西。(Errors是不应捕获的)

  异常分为Checked Exception和Unchecked Exception。

  CheckedException是除了RuntimeException外所有Exception及其子类,UncheckedException是RuntimeExcetion及其子类。

CheckedException需要使用throws处理,而UncheckedException无须使用throws处理。此处的Checked意思是Checked by coder。

UnCheckedException可以由compiler在运行propagate outside the method or constructor boundary,我们就不必处理了,如

IndexOutofBoundException,ArythmeticException。而FileNotFoundException,SqlBadSyntax之类的在编译阶段是没法处理的,因此

我们必须手动处理。

 

posted @ 2018-08-20 14:31  BraveSpringer  阅读(113)  评论(0编辑  收藏  举报