Created
December 12, 2014 03:15
-
-
Save jackdempsey/a78916919aad71133faa 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
puts "Example 1: No rescue inside loop" | |
begin | |
5.times do |i| | |
begin | |
p i | |
raise "loop stops here" | |
end | |
end | |
rescue => e | |
puts "error caught here: #{e}" | |
end | |
puts "\nExample 2: Rescue inside loop" | |
begin | |
5.times do |i| | |
begin | |
p i | |
raise "loop stops here, no more looping" | |
rescue => e | |
puts "caught here, loop keeps on truckin" | |
end | |
end | |
rescue => e | |
puts "error caught here: #{e}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Example 1: No rescue inside loop
0
error caught here: loop stops here
Example 2: Rescue inside loop
0
caught here, loop keeps on truckin
1
caught here, loop keeps on truckin
2
caught here, loop keeps on truckin
3
caught here, loop keeps on truckin
4
caught here, loop keeps on truckin