public class Test { public void f() throws MyException { try { g(); } catch (MyException e) { System.out.println(e.getMessage()); throw e; } } public void g()throws MyException { throw new MyException("我的异常!"); } public static void main(String[] args) { try { new Test().f(); } catch (MyException e) { System.out.println(e.getMessage()); } } public class MyException extends Exception { public MyException(String s) { super(s); } } }

评论