Java Review SectionⅡ 异常处理

异常处理

package Chapter0827;

public class MyException {
    public static void getException() {
        try {
            int[] a = new int[3];
            a[3] = 0;
            System.out.println("----异常后的逻辑----");
        } catch (Exception e) {
            System.out.println("----" + e.getStackTrace() + "----");
            //System.exit(0);//退出虚拟机 finally不执行
            return;//return finally依然执行
        } finally {
            System.out.println("----finnaly执行了。----");
        }
    }

    public static void main(String[] args) {
        getException();
    }
}

如果在finally之前有return控制符,finally依然执行

throws——抛出异常,不负责任

Main方法不要throws异常---------------抛给JVM,不负责任的表现)

2018.8.27

猜你喜欢

转载自blog.csdn.net/Altr1aPendrag0n/article/details/82107039