# Rescuing exceptions with "redo"

**URL:** <https://www.ruby-forum.com/t/rescuing-exceptions-with-redo/97632>\
**Category:** Ruby\
**Created:** [July 8, 2006, 9:37pm UTC](https://www.ruby-forum.com/t/rescuing-exceptions-with-redo/97632 "2006-07-08T21:37:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [July 8, 2006, 9:37pm UTC](https://www.ruby-forum.com/t/rescuing-exceptions-with-redo/97632/1 "2006-07-08T21:37:14Z")

</div>

Hi aaall,

I have a code like this (from Why’s (poignant) guide to Ruby, in  
[http://poignantguide.net/ruby/chapter-5.html#section5](http://poignantguide.net/ruby/chapter-5.html#section5)):

* * *

class LotteryTicket  
NUMERIC\_RANGE = 1…25

attr\_reader :picks  
def initialize( \*picks )  
if picks.length != 3  
raise ArgumentError, “three numbers must be picked”  
elsif picks.uniq.length != 3  
raise ArgumentError, “the three picks must be different numbers”  
elsif picks.detect { |p| not NUMERIC\_RANGE === p }  
raise ArgumentError, “the three picks must be numbers between 1  
and 25.”  
end  
@picks = picks

end

def LotteryTicket.new\_random  
new( rand( 25 ) + 1, rand( 25 ) + 1, rand( 25 ) + 1 )  
rescue ArgumentError  
redo  
end

end

ticket = LotteryTicket.new\_random()

* * *

When the 3 random numbers created in this last line are not equal,  
everything goes right. However, when two or three are identical, the  
second argument error is raised and, theoretically, the method  
“new\_random” should be run automatically again. However, an exception  
cames out:

in `new\_random’: unexpected redo (LocalJumpError)

This exception should not be launched… (I thought). Suggestions?
