来自不同线程上的异常的 StackTrace?
StackTrace 上有一个构造函数,它将异常作为参数。一切都很好,但我注意到所有其他构造函数都说它将从当前线程获取 StackTrace,但是接受异常的构造函数除了
生成的堆栈跟踪描述了 当时的堆栈 异常。
我只是想确保,即使当我从另一个线程中的异常创建 StackTrace 时,我在创建异常的不同线程上创建 StackTrace,我也会获得正确的异常 StackTrace。
有人可以确认一下吗?
There is a constructor on StackTrace that takes an exeption as an argument. All fine and well, but I noticed that all the other constructors say that it will get the StackTrace from the current thread, but the constructor taking the exception does not say anything about that other than
The resulting stack trace describes
the stack at the time of the
exception.
I just want to be sure that I will get the correct StackTrace of an exception even if I create the StackTrace on a different thread that the exception was created in when I create the StackTrace from an exception in another thread.
Can someone please confirm?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来很容易尝试,除非我错过了一些东西。这会为我打印正确的堆栈跟踪。
Seems easy enough to try, unless I'm missing something. This prints the right stack trace for me.
它将为其调用的线程创建 StackTrace(在内部,它使用参数“targetThread”调用“CaptureStackTrace”,该参数指示当前线程被请求)。为另一个线程创建的唯一构造函数是采用 Thread 实例的构造函数。
It will create the StackTrace for the thread it's called on (internally, it calls 'CaptureStackTrace' with for the parameter 'targetThread', which indicates the current thread is requested). The only ctor which creates for another thread is the one which takes a Thread instance.