How do i get ruby to output an exception inside a thread?
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.
精彩评论