Blow - это пример, скопированный с Think in Java 4 edition
public class Rethrowing {
public static void f() throws Exception {
System.out.println("originating the exception in f()");
throw new Exception("thrown from f()");
}
public static void h() throws Exception {
try {
f();
} catch (Exception e) {
System.out.println("Inside h(),e.printStackTrace()");
e.printStackTrace(System.out); //first print line throw (Exception) e.fillInStackTrace();
}
}
public static void main(String[] args) {
try {
h();
} catch (Exception e) {
System.out.println("main: printStackTrace()");
e.printStackTrace(System.out);
}
}
}
Output:
originating the exception in f()
Inside h(),e.printStackTrace()
java.lang.Exception: thrown from f()
at Rethrowing.f(Rethrowing.java:20)
at Rethrowing.h(Rethrowing.java:25)
at Rethrowing.main(Rethrowing.java:35)
main: printStackTrace()
java.lang.Exception: thrown from f()
at Rethrowing.f(Rethrowing.java:20)
at Rethrowing.h(Rethrowing.java:25)
at Rethrowing.main(Rethrowing.java:35)
When comment //first print line
Output:
originating the exception in f()
Inside h(),e.printStackTrace()
main: printStackTrace()
java.lang.Exception: thrown from f()
at Rethrowing.h(Rethrowing.java:29)
at Rethrowing.main(Rethrowing.java:35)
У меня вопрос, почему я сначала вызываю метод e.printStackTrace (printOut out) перед методом fillInStackTrace, а затем, кажется, fillInStackTrace недоступен. Любой может сделать меня лихорадкой, спасибо заранее.