[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: unwind_protect & try/catch combined corner case
From: |
Søren Hauberg |
Subject: |
Re: unwind_protect & try/catch combined corner case |
Date: |
Thu, 07 Jan 2010 12:50:38 +0100 |
tor, 07 01 2010 kl. 10:31 +0100, skrev Jaroslav Hajek:
> On Thu, Jan 7, 2010 at 10:19 AM, Soren 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.
Soren
unwind_protect & try/catch combined corner case, John W. Eaton, 2010/01/07