octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unwind_protect & try/catch combined corner case


From: Jaroslav Hajek
Subject: Re: unwind_protect & try/catch combined corner case
Date: Thu, 7 Jan 2010 10:31:38 +0100

On Thu, Jan 7, 2010 at 10:19 AM, Søren Hauberg <address@hidden> wrote:
> tor, 07 01 2010 kl. 09:46 +0100, skrev Jaroslav Hajek:
>> But is the former correct? I believe it's the most reasonable behavior:
>> the "try" section is entered, then unwind_protect. An interrupt occurs
>> there, hence control is transferred to unwind_protect_cleanup.
>> unwind_protect_cleanup executes some code which finally raises an
>> error;
>
> I'm with you so far...
>
>>  however, this error is suppressed because we're in a "try"
>> section.
>
> I don't understand this. If you raise an error, shouldn't it be caught?

Yes. Essentially it is caught (which is why it doesn't show up), but
the handler never executes, because it is immediatelly interrupted.

> I think I would expect the following output from your program:
>
>  cleanup inner
>  caught error
>  cleanup outer
>

Why? Please explain.

> I haven't tried your current code, but what is the result if the
> following program?
>
>  unwind_protect
>    fdisp (stderr, "Press Ctrl-C");
>    pause (3);
>  unwind_protect_cleanup
>    svd () # this raises an error
>  end_unwind_protect
>
> Will the user get the error message from 'svd' (which would be quite
> helpful for debugging)?

Yes, unless it is caught by "try".

> Will the user be able to catch this error?
>

No. At least, not when the user presses Ctrl-C; see the previous
explanation. You try to catch an error and what arrives is both an
interrupt and an error. The interrupt wins. Unlike error, interrupt
can't be suppressed.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]