Stack unwinding and destructors?

From: Steven T. Hatton (susudata_at_setidava.kushan.aa)
Date: 08/09/04

Date: Mon, 09 Aug 2004 14:07:46 -0400

On page 366 of TC++PL(SE) we are told " The destructor will be called
independently of whether the function is exited normally or exited because
an exception is thrown."

On page 382 the following appears:

"Consider the simple function f() that appears to have nothing to do with
exception handling:

void g(int);

void f()
  string s;

However, g() may throw an exception, so f() must contain code ensuring that
s is destroyed correctly in case of an exception."

These statements seem mutually inconsistent. Would it have been more
correct to use 'string* s = new string();' in place of "string s;"?

Hatton's Law: "There is only One inviolable Law"
KDevelop:  SuSE:

Relevant Pages

  • exit, signals and exceptions
    ... a signal handler. ... Project.exe faulted with message "application-defined exception". ... void closesockets ... _closesocket's destructor ...
  • [patch v2] x86: Add testcases for RODATA and NX protections/attributes
    ... +config DEBUG_RODATA_TEST ... this implies having dynamic exception handling table entries. ... +static void test_exit ...
  • Re: compile error about destructor
    ... void f2 ... you cares about whether the destructor of local will be ... When there is structured exception thrown, I think even if you do not put ... What do you mean separate the __try block into another function? ...
  • Re: Object reference not set to an instance of an object.
    ... > The event handler WTGDataRowReady10Handler is called by a delegate in the ... > catch (Exception ex) ... > private void WTGDataRowReady10Handler( ...
  • Re: N1298 - try/finally for C
    ... Using a void*, or something containing a void*, gives ... Then we have a function that potentially throws an exception: ... If you mean some custom allocator, then we generally need to pass yet ... As for function pointers, and besides that throwing function pointers ...