Mega Code Archive

 
Categories / Ruby / Threads
 

Rescue the exception at the time the threads are joined

threads = []  4.times do |number|      threads << Thread.new(number) do |i|          raise "Boom!" if i == 2          print "#{i}\n"      end  end  threads.each do |t|      begin          t.join      rescue RuntimeError => e          puts "Failed: #{e.message}"      end  end