From: Glen Holcomb Date: 2008-10-02T00:22:15+09:00 Subject: Re: "ensure" hiding actual error ------=_Part_10479_13102427.1222874604153 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wed, Oct 1, 2008 at 9:08 AM, Nit Khair wrote: > Robert Klemme wrote: > > 2008/10/1 Thomas B. : > >> Nit Khair wrote: > >>> Now in real life, "@test = " calls a method elsewhere which may call > >>> other methods. So i am clueless as to where the error actually is. > >> > >> You caused another exception inside your ensure clause, so the previous > >> one got lost, so that's your mistake. If you want the original exception > >> to live to tell the tale, you cannot raise another in your ensure > >> clause. But if your ensure clause was correct, there wouldn't be any > >> problems with handling correctly the original exception. > > > > I am not following you. How have i caused another exception in the > ensure clause. I am not raising an exception in the ensure. The ensure > clause only has some statement to free resources. as in : > > > begin > my_form = create_.... > > ensure > my_form.free_form. > ... > end > What happens here if my_form never got a value because there was an error previous that made create_... invalid? What Thomas is saying is that there is an exception being raised by the code present in your ensure block. > > > In the example i gave you, the stderr.print is printing the error from > above, but in my original ncurses program, it seems to directly go to > the ensure. > > Let's say in my ensure I said: > > my_form.free_form if !my_form.nil? > then the program would just terminate silently. > > > > Adding to that: an uninitialized variable does not cause a syntax > > error. IIRC initially this was about a syntax error. > > > > Okay, i was trying to give you a simple example. Sometimes it is a > variable - i may misspell it, or in some cases it is a syntax error. > > Even currently as I am refactoring my code, I am sometimes getting the > correct error, sometimes I have to comment out "ensure" to get the > error. > > > Cheers > > > > robert > > Perhaps I should ask the question differently. Am i doing something > wrong, am i using the ensure clause incorrectly (the samples I started > with released these structures in the ensure). This is my first major > ruby app. > Thanks a lot for your time, Robert! > -- > Posted via http://www.ruby-forum.com/. > > -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_10479_13102427.1222874604153--