From: Joel VanderWerf Date: 2008-02-09T03:48:36+09:00 Subject: Re: Timeout::Error Jeremy Thurgood wrote: > Joel VanderWerf wrote: >> Nobuyoshi Nakada wrote: >>> Sorry, I can't remember it correctly now. Perhaps, not to >>> happen to be caught accidentally. >> >> That sounds like a good reason: > > Not to me. I would expect catching StandardError (implicitly or > explicitly) would catch everything I have a reasonable chance of > recovering from, including timeouts. This is my standard strategy when I > am not entirely sure what exceptions may be thrown by third-party code. > There is code in the standard library that throws TimeoutErrors that > need to be caught explicitly: > > require 'open-uri' > begin > my_file = open("http://www.example.com/file") > rescue > puts "Sorry, I couldn't open the URL." > end > > In this case, everything /except/ a timeout will be caught. This is > inconsistent and confusing behaviour to me, especially as it is not > properly documented anywhere that I have seen. It not a question of _what_ is recoverable, but _where_ it should be recovered. A timeout should only be caught at a point where it's expected. What if only the outer rescue, below, were allowed to catch the timeout? begin Timeout.timeout do begin rescue # inner end end rescue # outer end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407