StackTraceElement[ ] tr;
try{
throw new Exception();
} catch(Exception e){
tr = e.getStackTrace();
}
//Do some track trace logging
The stack trace of any call is snagged via an exception so that the caller can be ascertained.
問下面哪個選項正確:
(A) An Exception cannot be instantiated outside of a real exception event
(B) Runtime().getRuntime().getStackTrace() is the proper call for this purpose
(C) StackTraceException is the correct class for this purpose
(D) Throwing the exception is unnecessary for retrieving its stack trace
(a)錯的,你可以任意實例化一個exception
(b)用Thread.currentThread().getStackTrace()就可以了。
(c)查遍google沒找到這個類
(d)對的,參考b