[Java]异常丢失
程序员文章站
2024-03-22 10:07:22
...
package test;
import java.io.IOException;
public class MyExceptionTest {
public static void f () throws MyException{
throw new MyException();
}
public static void f2 () throws MyNextException {
throw new MyNextException();
}
public static void main(String[] args) {
try {
try{
f();
} finally {
f2();
}
} catch (Exception e) {
e.printStackTrace(); //仅补货了f2抛出的异常(MyNextException)
}
try{
f(); //f()抛出了异常却没有输出
} finally {
System.out.println("hello world");
return;
}
}
}
class MyException extends Exception {
public MyException() {}
public MyException(String msg) {
super(msg);
}
}
class MyNextException extends Exception {
}
上一篇: D2学习