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
An AppDomainUnloadedException is thrown in a thread because the application domain in which the thread is executing is being unloaded. The common language runtime or a host process terminates the thread by throwing an internal exception.
If an unhandled exception occurs in the main thread of an application, the main thread terminates, along with your entire application. An unhandled exception in a spawned worker thread, however, will terminate only that thread.
Ruby makes it easy to write multi-threaded programs with the Thread class. Ruby threads are a lightweight and efficient way to achieve concurrency in your code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With