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 13:36:19 +0100

On Thu, Jan 7, 2010 at 12:50 PM, Søren Hauberg <address@hidden> wrote:
> tor, 07 01 2010 kl. 10:31 +0100, skrev Jaroslav Hajek:
>> 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.
>
> So, you catch an error, but don't run the handler. This just seems
> somewhat awkward to me. I can understand the reasoning behind this, but
> it does seem somewhat weird. Perhaps it would be better never to catch
> errors raised inside 'unwind_protect_cleanup'.
>
>> > I think I would expect the following output from your program:
>> >
>> >  cleanup inner
>> >  caught error
>> >  cleanup outer
>> >
>>
>> Why? Please explain.
>
> Now, that I think about it, I agree that this output should not be
> expected. I just really find the "catch errors, but don't treat them"
> situation odd.
>

Well, the situation is odd by itself, because it makes Octave handle
an interrupt and an error at the same time.
I agree that at the first glance one would expect the handler to be
invoked. That is what happens when you substitute "return" in place of
the "press Ctrl-C" block. But I think the purpose of interrupt should
simply bring you as fast and cleanly as possible to the command line.
No further code is going to be executed except unwind_protect
cleanups, so I think it doesn't matter that an error is suppressed but
the handler not actually run.

Note that the wrong behavior of older Octave only occurs when "pause"
is interrupted, for instance, if you delete the "pause" call and
instead uncomment the following three lines, you'll get:

octave:1> tea1
press Ctrl-C
18023^C
cleanup inner
cleanup outer

i.e. the same behavior as with the recent changes. So, at least these
changes don't break anything. Maybe the whole matter is just too much
of a corner case for anyone to really care.

regards

-- 
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]