From: Panagiotis Atmatzidis Date: 2012-01-13T22:26:25+09:00 Subject: Re: Problem with "Exception" - suddenly stopped working Hello, On 13 Ιαν 2012, at 13:22 , Peter Vandenabeele wrote: > On Fri, Jan 13, 2012 at 12:23 PM, Abinoam Jr. wrote: > >> On Thu, Jan 12, 2012 at 8:45 PM, Panagiotis Atmatzidis >> wrote: >>> Hello, >>> >>> thanks all for the answers. >>> >>> On 12 Ιαν 2012, at 22:35 , Peter Vandenabeele wrote: >>> >>>> On Thu, Jan 12, 2012 at 10:33 PM, Peter Vandenabeele < >> peter@vandenabeele.com >>>>> wrote: >>>> >>>>> Very speculative ... could you ask it's ancestor tree? >>>>> >>>>> Twitter::Error::BadGateway.class >>>>> >>>> >>>> Correction >>>> >>>> Twitter::Error::BadGateway.ancestors >>>> >>>> that is ... >>>> >>>> Peter >>> >>> >>> Here is the ancestors output: >>> >>> greyjewel:Morula atma$ cat test.rb && ruby1.9 test.rb >>> require "twitter" >>> puts Twitter::Error::BadGateway.ancestors >>> [...] >>> Twitter::Error::BadGateway >>> Twitter::Error::ServerError >>> Twitter::Error >>> StandardError >>> Exception >>> Object >>> Kernel >>> BasicObject >>> greyjewel:Morula atma$ >>> >>> So my error is "BadGateway" but should I use this like: >>> >>> [...] >>> rescue Exception => (Twitter::Error::BadGateway) >> > > I think that should be (untested) > > rescue Twitter::Error => e > > and then you can do usefull things with 'e', preferably based on it's class. > > e.to_s > e.class Thanks for the hint. Doesn't work though. The script comes out with the same error. > >> [...] >>> >>> I'm not sure where to go from here. >> >> (Bottom commenting. Thanks Peter). >> >> If you put Twitter::Error::BadGateway it'll treat only this particular >> error. >> >> And there's much more. >> >> Look at the ones raised by the twitter gem itself. >> >> https://github.com/jnunemaker/twitter/tree/master/lib/twitter/error >> >> > Indeed. Thanks for that pointer. > > So it seems > > rescue Twitter::Error should catch all exceptions from the Twitter gem. > > Curious if the OP was able to solve the problem now with mentioning an > explicit Exception class? > > HTH, > > Peter Thanks for the explanations. As a result I got a deeper understanding of exceptions than before. However, I think the problem lies elsewhere. The prior code had just a 'rescue' clause. As Peter said, it should work with "Exception => e" also, although I don't have any interest in printing the error here. I'm using 'retry' for 3 times, then the program exists with a message. I have the feeling that for some reason the script breaks before reaching the rescue keyword. Thanks for the help. I'll probably re-write the function from scratch, see if I get the same errors. Here is the entire script: http://codepad.org/5T32AAXW best regards > > -- > Peter Vandenabeele > http://twitter.com/peter_v > http://rails.vandenabeele.com Panagiotis Atmatzidis ----------------------------- Pharmacy Student at VFU, Brno mailing lists: ml@convalesco.org personal info: http://www.convalesco.org The wise man said: "Never argue with an idiot, he brings you down to his level and beat you with experience."