Re: "ensure" hiding actual error



[Note: parts of this message were removed to make it a legal post.]

On Wed, Oct 1, 2008 at 9:08 AM, Nit Khair <sentinel.2001@xxxxxxx> wrote:

Robert Klemme wrote:
2008/10/1 Thomas B. <tpreal@xxxxxxxxx>:
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)

.



Relevant Pages

  • Re: Evaluating Exceptions, Try Except and Try Finally
    ... error occurs during execution. ... statementList2 (the finally clause) is executed. ... exception is raised during execution of statementList1, ... THE IF THEN ELSE STATEMENT DOCUMENTATION IS JUST AS FUCKED:)' ...
    (alt.comp.lang.borland-delphi)
  • Re: Finally in IE
    ... If an exception is thrown, each catch clause is inspected in turn ... the clause executes wether or not an exception is thrown ... Firefox considers your <script> block as self-enclosed system. ...
    (comp.lang.javascript)
  • Re: "ensure" hiding actual error
    ... Robert Klemme wrote: ... You caused another exception inside your ensure clause, ... problems with handling correctly the original exception. ...
    (comp.lang.ruby)
  • [Proposal] using statement enhancements
    ... Mostly always you use the using clause you deal with native ressources, ... exception handlinjg is sooner or later inevitable. ... Rollback(); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Try Finally...
    ... > language than risk that happening. ... You're well versed in Windows exception handling, ... clause should handle a non-fatal exception. ... to non-fatal exceptions than they do now. ...
    (comp.lang.pascal.delphi.misc)