From: Hugh Sasse Date: 2005-11-03T04:44:14+09:00 Subject: Re: Trapping errors. On Thu, 3 Nov 2005, Robert Klemme wrote: > Hugh Sasse wrote: > > On Thu, 3 Nov 2005, Robert Klemme wrote: > > > > > Hugh Sasse wrote: > > > > On Thu, 3 Nov 2005, Robert Klemme wrote: > > > > > > > > > Hugh Sasse wrote: > > > > > > I see my changes to fileutils are now in the Ruby CVS. > > > > > > However, even with > > > > > > rescue Exception, SystemCallError => e > > > > > > or > > > > > > rescue Exception, Errno::EACCES, Errno::EBUSY => e > > > > > > > > > > > > I still cannot trap this error. From the call stack this part of > > > > > > the code is being used, so why won't the error cause ruby to go > > > > > > back up the callstack until it finds this rescue clause? > > > > > > > > > > Maybe there's another rescue clause that is closer to the place > > > > > where the exception is thrown... > > > > > > > > But unless I have completely misunderstood the point of rescue, even > > > > if that calls raise, the exception will still be caught by my > > > > enclosing rescue. > > > > > > But who guarantees that the other rescue clause actually throws > > > again? If it doesn't you can't catch it. > > > > > > .... > > > rescue Exception => e > > > puts "Catch me if you can >:-}" > > > end > > > > > > ;-) > > > > > > > Then it's already caught, and I should never see the error. > > Why not? If it's printed in the other rescue clause you would see it. Or am > I missing something here? I wouldn't see it as an error which kills my program. It would have been caught, and dealt with, or caught and re-raised, in which case the outer block would catch it. 1 We have established that a begin...rescue...end block will rescue any errors raised inside it, provided the rescue clause matches that error type. 2 We have established that if a begin ... rescue ... raise ... end block re-raises an error, it can be caught by a surrounding begin...rescue...end block 3 My case is that I have a begin part1 rescue Exception, SystemCallError, Errno::EACCES, Errno::EBUSY => e part2 end block and it is not catching a Errno::EBUSY error from part1: The error crashes the program. So: If that error has been raised in part1, and not caught in part1 then I should be able to catch it. If that error has been raised in part1, and caught in part1, part2 should never come into play, and the program should continue 4 How can a subclass of Exception not be caught by Exception? 5 Why doesn't SystemCallError catch it? 6 Why doesn't the Errno::%s form catch it? i.e everything between "Exception" and " =>" should be unnecessary, but even with those it doesn't catch the error. > > robert > Hugh