Tyler Gillies
Tyler Gillies

Reputation: 1907

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 app just quietly ignores it

Upvotes: 7

Views: 1290

Answers (2)

Andrew Grimm
Andrew Grimm

Reputation: 81510

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.

Upvotes: 3

Nikita Rybak
Nikita Rybak

Reputation: 68006

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

Upvotes: 3

Related Questions