-
-
Save emmx/0178dc758501bdfe238a36ab69b9d69b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thread.abort_on_exception = true | |
begin | |
t1 = Thread.new do | |
t2 = Thread.new do | |
sleep 5 | |
puts "RAISE" | |
1/0 | |
end | |
sleep 3 | |
puts "WAITING T2" | |
t2.join | |
end | |
sleep 1 | |
puts "WAITING T1" | |
t1.join | |
rescue => e | |
puts "ERROR "+e.message | |
end | |
puts "FINISHED" | |
######################## | |
# TWO POSSIBLE OUTPUTS | |
######################## | |
# | |
# Case A | |
# | |
# WAITING T1 | |
# WAITING T2 | |
# RAISE | |
# ERROR divided by 0test.rb:8:in `/': divided by 0 (ZeroDivisionError) | |
# from test.rb:8:in `block (2 levels) in <main>' | |
# | |
######################## | |
# | |
# Case B | |
# | |
# WAITING T1 | |
# WAITING T2 | |
# RAISE | |
# ERROR divided by 0 | |
# FINISHED | |
# | |
######################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment