audioteechnica
2015-03-08 15:11
采纳率: 100%
浏览 2.9k
已采纳

关于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条回答 默认 最新

  • blownewbee 2015-03-08 15:59
    已采纳

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

    点赞 打赏 评论

相关推荐 更多相似问题