Brian Candler wrote: > I was just caught out by this odd behaviour: a 'rescue' clause doesn't > generate an error if given a non-exception class. I had actually written > rescue Timeout > which was silently accepted but didn't work. Actually it should have been > rescue TimeoutError > > The following snippet demonstrates: > > ---- 8< ---------------------------------------------------- > require 'timeout' > > begin > rescue Timeout # this line is accepted > end > > raise Timeout # but this line is not: > # "exception class/object expected (TypeError)" > ---- 8< ---------------------------------------------------- > > So, perhaps 'rescue' should check that its parameter is_a?(Exception). Does > it have any meaning to use rescue with a non-exception class? I think I've been bit by that one too. Timeout vs. TimeoutError. When would the check be preformed? At the time the code is eval-ed, we may not know the exception class[1]. At the time the begin-end clause starts to execute, we don't yet know which (if any) rescue clause will be used, so it may waste time. And we may still not know the actual class (swap the first two lines of [1]). At the time an exception is handled, I guess it could be done, but wonder what the cost would be (especially with multiple rescue clauses). Maybe this could be a $DEBUG thing? [1] As in this case: x = ArgumentError begin raise ArgumentError rescue x => ex p ex end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407