关于Exception, stack trace的一道问题

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

1个回答

(a)错的,你可以任意实例化一个exception
(b)用Thread.currentThread().getStackTrace()就可以了。
(c)查遍google没找到这个类
(d)对的,参考b

audioteechnica
audioteechnica 太谢谢了!
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐