Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-10-11 15:13:12


Peter Dimov wrote:
>
> Alexander Terekhov wrote:
> > Peter Dimov wrote:
> > [...]
> >> You can't have it both ways.
> >
> > Sure you can. That's "the beauty" of 2-phase EH.
>
> Sorry, I don't see it. To search for a handler, you need stack frames. To
> omit the stack frame (and make the function a candidate for inlining), you
> need to prove statically that nothing performed by this function will throw.

Nope.

> But how can you do that in a world where everything can throw?
>
> void h(int) throw();
>
> void f() throw()
> {
> h(5); // #1: can throw stack_ovf_e
> }
>
> void g()
> {
> try { f(); } catch(stack_ovf_e) { /**/ }

Bad example. Stack overflow is no problem on *entry* to a throw()
region ("call instruction" for f() invocation in g()). You really
*can* catch it here (but not from your "#1"). You'll simply have
a sort of __try/__except(invoke_unexpected()) protected range for
the entire throw()-region (apart from stack overflow on its entry).
Imagine that compiler *knows* the size of stack needed for f()
(the entire call chain) and we just can't live with a possibility
that stack overflow can terminate us inside the throw() region...
and we can live with the overhead of stack checks.

void g() {
  try {
    __check_stack(AMOUNT_NEEDED); // throws stack_ovf_e
    // MS SEH
    __try {
      f();
      f();
      f();
    }
    // triggers std::unexpected handling
    __except(invoke_unexpected()) {}
  }
  catch(stack_ovf_e) { /**/ }
}

> }
>
> If you omit f()'s stack frame, #1 will find the catch.
>
> >> Either stack overflow et al are C++
> >> exceptions and everything can throw, hence stack frames are always
> >> required, or throw() specs have no cost if static analysis can prove
> >> the code doesn't throw. Pick one. :-)
> >
> > http://groups.google.com/groups?selm=3D661874.F3A00006%40web.de
> > (Subject: Re: C++ exception handling)
> >
> > http://groups.google.com/groups?selm=3E0C27B6.1D7EC741%40web.de
> > (Subject: Re: C++ stack overflow and exception safety)
> >
> > (Don't miss a "#pragma unexpected_exception" embedded link)
> >
> > Questions?
>
> These links clarified nothing for me.

Hmmm.

regards,
alexander.

--
http://groups.google.com/groups?selm=3F868710.C9488647%40web.de
(Subject: Re: Stack vs. Heap)

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk