# Rescuing exceptions with "redo"

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

---

<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:52pm UTC](https://www.ruby-forum.com/t/rescuing-exceptions-with-redo/102964/2 "2006-07-08T21:52:32Z")

</div>

On Jul 08, 2006, at 8:37 pm, Damaris F. wrote:

> 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?

He must have meant to type “retry” instead of “redo”. redo is for  
loops only AFAIK

Ashley

---

<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, 10:55pm UTC](https://www.ruby-forum.com/t/rescuing-exceptions-with-redo/102964/3 "2006-07-08T22:55:38Z")

</div>

Yes! It works fine with retry! Thanks! 😃

Ashley M. wrote:

> On Jul 08, 2006, at 8:37 pm, Damaris F. wrote:
> 
> > 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?
> 
> He must have meant to type “retry” instead of “redo”. redo is for  
> loops only AFAIK
> 
> Ashley

---

<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 12, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/rescuing-exceptions-with-redo/102964/4 "2006-07-12T16:20:17Z")

</div>

On 8-jul-2006, at 21:37, Damaris F. wrote:

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

Maybe he mistyped and meant “retry” instead?
