欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[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 {

}

相关标签: Java 编程思想