From: thefed Date: 2007-11-08T05:14:20+09:00 Subject: Re: Rambling: try/catch On Nov 7, 2007, at 1:45 PM, Casimir P wrote: > Just had an vague idea about generic java "try-catch" converted to > ruby- > world I would like some feedback on. > > I'm building a "microscopic CMS" system to learn more ruby, and of > course > it would be good to implement proper error catching system. Try- > catch is > what java uses. > > Now the vague idea was to create one error catching function, and to > throw all things that might fail (say loading a file) "through" that > function. Passed as a code block? I am not sure, it keeps slipping > from > me. :) I **think** this is what you're looking for: begin # do something useful... rescue => e # do something with the error 'e' end To keep rescue code short, you could have a function: error_function = lambda { | error | #do something useful... } and then for rescue... begin .... rescue => e error_function[e] end Tadah! HTH, ari