f



Re: retry does not work

Guy Decoux:

>  Well the example was probably
> 
>    def resume_example(x)
>       print x
>       x += 4
>       begin
>          raise if x < 10
>          print x
>       rescue
>          x = 10
>          retry
>       end
>       puts
>    end
 
you have refactored my code to achieve the result. is all code so easily refactored?

    def i_am_libaray_code
      # this is a library call
      # to be used in many differnt apps
      # do not add user interface code!
      raise SpecialWaring, "Warning, incoming!"
      ...
    end

    def resume_example(x)
       begin
          i_am_library_code
       rescue SpecialWaring => e
          puts e
          resume
       end
    end

i can not refactor the lib call to conatin stdout, and i need a message from it about its status. perhaps there is another way to do this. if you know please tell! 

-t0

0
transami (959)
11/20/2003 10:31:00 AM
comp.lang.ruby 48868 articles. 0 followers. Post Follow

3 Replies
412 Views

Similar Articles

[PageSpeed] 3

>>>>> "T" == T Onoma <transami@runbox.com> writes:

T> i can not refactor the lib call to conatin stdout, and i need a message
T> from it about its status. perhaps there is another way to do this. if
T> you know please tell!  

 Becuase you can't refactor the library, you *can't* use resume like you
 want use it because you know nothing about the internal of this library



Guy Decoux



0
decoux (1351)
11/20/2003 10:37:24 AM
"T. Onoma" <transami@runbox.com> schrieb im Newsbeitrag
news:E1AMm57-0002fp-HX@odie.runbox.com...
> Guy Decoux:
>
> >  Well the example was probably
> >
> >    def resume_example(x)
> >       print x
> >       x += 4
> >       begin
> >          raise if x < 10
> >          print x
> >       rescue
> >          x = 10
> >          retry
> >       end
> >       puts
> >    end
>
> you have refactored my code to achieve the result. is all code so easily
refactored?
>
>     def i_am_libaray_code
>       # this is a library call
>       # to be used in many differnt apps
>       # do not add user interface code!
>       raise SpecialWaring, "Warning, incoming!"
>       ...
>     end
>
>     def resume_example(x)
>        begin
>           i_am_library_code
>        rescue SpecialWaring => e
>           puts e
>           resume
>        end
>     end
>
> i can not refactor the lib call to conatin stdout, and i need a message
from it about its status. perhaps there is another way to do this. if you
know please tell!

What strikes me is that you use "resume" in the rescue clause instead of
"retry".  Is that on purpose or is maybe a simple misspelling the reason
for your frustration.

Kind regards

    robert

0
bob.news (3807)
11/20/2003 10:38:20 AM
Hi,

In message "Re: retry does not work"
    on 03/11/20, "T. Onoma" <transami@runbox.com> writes:

|you have refactored my code to achieve the result. is all code so easily refactored?

Not all, but most.

Your "resume" makes exception handling much harder.  With "resume",
every raise can be re-entered, that means programmers need to care
about re-entrance always.

So allowing new thing is not always a good thing.

							matz.

0
matz (1855)
11/20/2003 10:50:57 AM
Reply: