Why this exception is not caught?

Hi,

this code works as expected:

class RetryException < RuntimeError; end;

class Something
def do_something
    @i = 3
    begin
        get_data(@i)
    rescue RetryException => detail
        p "Retry exceptionxxxx"
        @i += 1
        retry if detail.ok_to_try
    rescue
        p $!
    end
end

def get_data(local_i)
    local_i.upto(10) do|t_i|
        if t_i == 5
            raise RetryException.new(true),"Retry exception"
        end
        p t_i
    end
end

However, if i change second method:

begin
        timeout(6) do
            ret_data = @proxy_con.gets()
        end
        second_part = ret_data.split('##')[1].split(',')
        last_part = second_part[-1]
        ret_echo_id = last_part.split('=')[1]
        #ret_echo_id = "foobar"
        second_part.delete_at(-1)
        second_part = second_part.join(',')
        p ret_echo_id

        if @v_echo_id != ret_echo_id
            raise RetryException #line 94
        end

        first_part = ret_data.split('##')[0]
        ret_data = first_part + "##" + second_part +"##"
    rescue Timeout::Error
        raise "Timeout Error"
    rescue
        raise "Some other error"
    end

In this case, when the exception is raised on line # 94, then in the calling
method...it is handled as general rescue...and its not handled as Exception
of Class RetryException.However, if i remove the last rescue statement in
the second method it works alright.

···

--
---
The Road goes ever on and on
Down from the door where it began.
Now far ahead the Road has gone,
And I must follow, if I can,
Pursuing it with eager feet,
Until it joins some larger way
Where many paths and errands meet.
And whither then? I cannot say.

Because that second rescue statement catches any exception which is a
subclass of StandardError, so it catches the RetryException.

Then the statement

     raise "some other error"

raises a RunTimeError with "some other error" as a message.

So the outer method sees the RunTimeError and not the original RetryException.

···

On 9/11/06, Hemant . <inxs.hemant@gmail.com> wrote:

In this case, when the exception is raised on line # 94, then in the calling
method...it is handled as general rescue...and its not handled as Exception
of Class RetryException.However, if i remove the last rescue statement in
the second method it works alright.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/