首页 > 代码库 > 异常处理

异常处理

异常处理

代码如下:

package day09;

public class TestException {
public static void main(String[] args) throws Exception {
try {
method1();
System.out.println("statement1");
} catch (MyException1 e1) {
System.out.println("process ex1");
}
System.out.println("statement2");
}


private static void method1() throws Exception {
try {
method2();
System.out.println("statement3");
} catch (MyException2 e2) {
System.out.println("process ex2");
}
System.out.println("statement4");
}


private static void method2() throws Exception {
try {
method3();
System.out.println("statement5");
} catch (MyException3 e3) {
System.out.println("process ex3");
}
System.out.println("statement6");
}


private static void method3() throws Exception {
throw new MyException2();
}
}

 

异常处理