From: Robert Klemme Date: 2004-04-02T17:44:25+09:00 Subject: Re: error handling "Mark Hubbart" schrieb im Newsbeitrag news:82DA4958-8456-11D8-97DE-000502FDD5CC@mac.com... > > On Apr 1, 2004, at 11:44 AM, Robert Klemme wrote: > > > > > "Mark Hubbart" schrieb im Newsbeitrag > > news:789AB92E-83FE-11D8-97DE-000502FDD5CC@mac.com... > > > > [...] > > > >> This looks like a bug... sqrt() is recursing too deeply here, 1461 > >> levels seems a bit excessive. What values are causing it to dump like > >> that? Could you give a specific example? > > > > I guess they are quite big so sqrt needs to many steps to identify the > > square root. > > Oh. I hadn't realized that sqrt was supposed to recurse that much at > all... even using two 60 digit numbers to create a Complex number to > take the square root of, I couldn't get sqrt to cause me any problems, > using 1.6.8... That was just a wild guess. I'd normally not expect sqrt to be written as recursive function at all. But the stacktrace seemed to indicate that. > >> Normally, you could catch an error like this: > >> > >> begin > >> 0 / 0 > >> rescue > >> puts "no dividing by zero in integer division!" > >> end > >> > >> .. but that doesn't work for me with a SystemStackError. I guess those > >> are always fatal errors. > > > > Works perfectly for me: > > > > irb(main):036:0> def rec; rec; end > > => nil > > irb(main):037:0> begin > > irb(main):038:1* rec > > irb(main):039:1> rescue SystemStackError => e > > irb(main):040:1> puts "Caught it: #{e.inspect}" > > irb(main):041:1> end > > Caught it: # > > => nil > > Okay, that's kind of surprising. It works for me too, but only if I > specify the error type like in your code... I tried it the other time > in the same way as my example code above, and it failed. I thought that > if you didn't specify the error type, it would catch anything; I thought that once, too. But I got wiser in the meantime. :-) > apparently that's not the case. "If you write a rescue clause with no parameter list, the parameter defaults to StandardError." http://www.rubycentral.com/book/tut_exceptions.html Regards robert