From: Jeremy Bopp Date: 2010-10-27T00:17:28+09:00 Subject: Re: error handling: two flavors? On 10/26/2010 9:54 AM, Grary Stimon wrote: > Hi, > > I recall reading somewhere (can't remember where) that there are two > flavors of error handling available in ruby: 1) for truly unexpected > contingencies, and 2) for other infrequent but expected contingencies. > > So, I expect a method to return a value, including nil. But > if the method cannot return a value, including nil, i want it to return > a result along the lines of 2), above. it's not that i didn't anticipate > the case that my method might not be able to return a value, including > nil, rather, if it can't then i need to know based on some indicator > other > than nil, which is a meaningful value for my method! > > can anyone refresh me on whether there are these two flavors of error > handling in ruby? It sounds like you're remembering reading about exceptions, catch, and throw: http://ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html In your case, I think you want to use exceptions. I know I haven't seen throw and catch used very often, especially not for the kind of error processing you're describing. -Jeremy