抛出异常以隐藏原始异常的位置
// 来自 时代Java - nowjava.com public class Main { public static void main(String[] args) { try { m1(); } catch (MyException e) { // Print the stack trace e.printStackTrace(); } } public static void m1() throws MyException { try { m2(); /* NowJava.com - 时 代 Java */ } catch (MyException e) { e.fillInStackTrace(); throw e; } } public static void m2() throws MyException { throw new MyException("An error has occurred."); } } class MyException extends Exception { public MyException() { super(); } public MyException(String message) { super(message); }