From: Nit Khair Date: 2008-10-02T21:39:17+09:00 Subject: Re: "ensure" hiding actual error Stefan Lang wrote: > 2008/10/1 Nit Khair : >>> What happens here if my_form never got a value because there was an >> >> Aaaah. so you mean if i check for my_form before freeing, then ... since >> no new exception is raised, the original exception will be displayed. >> So I _should_ say: > > Generally, the right way is to put the initialization _before_ > the begin/ensure block: > > resource = init_resource > begin > # do something with resource > ensure > resource.close > end > > If all you do in the ensure block is to clean up the resource, > it is useless to put the resource initialization in the begin/ensure > block, because if the initialization fails, there's nothing to > cleanup anyway. > > Stefan Very interesting answer. Let me be honest -- I've been lost as to where to start the begin block. Is there any guideline in ruby? I spent many years in Java where the style was: try { resource = init_resource } catch (exception) {} finally { resource.close } I was following that pattern. My apps basically: a. create fields, forms and windows. b. call key_handler loop c. cleanup resources when key_handler quits thanks a lot for valuable thoughts. -- Posted via http://www.ruby-forum.com/.