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;
  //...
  g(1);
  g(2);
}

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;"?

-- 
STH 
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org  SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org


Relevant Pages

  • exit, signals and exceptions
    ... a signal handler. ... Project.exe faulted with message "application-defined exception". ... void closesockets ... _closesocket's destructor ...
    (comp.lang.cpp)
  • [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 ...
    (Linux-Kernel)
  • 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? ...
    (microsoft.public.vc.language)
  • 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( ...
    (microsoft.public.dotnet.languages.csharp)
  • [RFC] Improved versioned pointer algorithms
    ... The orphan test is used in snapshot write and exception delete to ... The current method of determining whether a ghost exception is an ... its child count then the ghost exception is an orphan, ... void set_bit ...
    (Linux-Kernel)