开发者

How do i get ruby to output an exception inside a thread?

开发者 https://www.devze.com 2023-01-10 02:47 出处:网络
When I spawn a thread with Thread.new{} it looks like any exception that happens in that thread never sees the light of day, and the a开发者_如何学Gopp just quietly ignores itNormally, threads are iso

When I spawn a thread with Thread.new{} it looks like any exception that happens in that thread never sees the light of day, and the a开发者_如何学Gopp just quietly ignores it


Normally, threads are isolated from each other, so exception in one won't terminate the whole application.

But, although I never used them, Thread class has several abort_on_exception methods, even with some examples. They should do what you want.
http://corelib.rubyonrails.org/classes/Thread.html


Adding to Nikita's answer, you can also trigger the exception by calling thread.join on the thread you've generated.

If you run the program with the debug flag on (ruby -d), then you'll also abort when an unhandled exception is raised in a thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号