# Nested Exceptions

**URL:** <https://www.ruby-forum.com/t/nested-exceptions/60929>\
**Category:** Ruby\
**Created:** [May 18, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/nested-exceptions/60929 "2006-05-18T17:24:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [May 18, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/nested-exceptions/60929/1 "2006-05-18T17:24:10Z")

</div>

Can anyone tell me if Ruby supports nested exceptions correctly? I have  
tried finding documentation on this issue, but have come up emtpy  
handed. What I want to do is something along the lines of this.

begin  
Some common setup code that could cause an exception goes here  
…  
…  
for i in 0…x  
begin  
# Other exceptions may occur within the loop.  
rescue  
# If an exception occurs within the loop I want to handle  
the  
# exception and continue with the loop.  
end  
end  
end

thanks  
-joe

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [May 18, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/nested-exceptions/60929/2 "2006-05-18T17:56:17Z")

</div>

Does this answer your question?

[gus@gusmac gus]$ cat tmp/exception.rb  
#! /usr/bin/ruby

begin  
rand \> 0.5 and raise “Hi from Murphy!”  
10.times do |i|  
begin  
i%2 == 0 and raise “Yack, #{i} is even”  
rescue =\> e  
puts(“In loop exception: #{e.message}”)  
end  
end  
rescue =\> e  
puts(“Setup failed: #{e.message}”)  
end  
[gus@gusmac gus]$ ruby tmp/exception.rb  
Setup failed: Hi from Murphy!  
[gus@gusmac gus]$ ruby tmp/exception.rb  
In loop exception: Yack, 0 is even  
In loop exception: Yack, 2 is even  
In loop exception: Yack, 4 is even  
In loop exception: Yack, 6 is even  
In loop exception: Yack, 8 is even

Guillaume.

Le 18 mai 06, à 11:24, Joe S. a écrit :
