Topic: set_unexpected () and dtor


Author: "Alexander Nasonov" <Alexander.Nasonov@gdt.ru>
Date: Tue, 8 May 2001 16:11:15 GMT
Raw View
I tried to check modified version of Stroustrup's STC class (see The C++
Programming Language, 3rd edition,
section 14.6.3.1 - User Mapping of Exceptions) and I typed the class
implementation as a first step:

    // Warning: not compiled code
    class STC
    {
      typedef std::unexpected_handler handler;
      handler old_;
      STC ( const STC & );
      STC &operator= ( const STC & );
    public:
      STC (  handler  h ) throw ()
      {
        old_ = std::set_unexpected (  h );
      }
      ~STC () throw ()
      {
        std::set_unexpected ( old_ );
      }
  }; // class STC

And then I tried to run test program:

    // Warning: not compiled code
    class X {};
    class Y {};

    void f ()
    {
      throw Y;
    }

    void g () throw ( X )
    {
      STC stc ( &f ); // Assumed that dtor restores old handler after
exception handling
      throw Y; // throw unexpected exception and void f () should be called
    }

    int main ()
    {
      try
      {
        g ();
      }
      catch ( ... ) {}
      return 0;
    }

But egcs-2.91-66 use old unexpected_handler inside void g (). This happens
because destructors
are called before unexpected_handler call. What standard says about this
situation? I tried to lookup
in the draft (http://www.cygnus.com/misc/wp/dec96pub/) but didn't found
nothing related to the problem.

All above is my own opinion
--------------------------------------------------------
Alexander Nasonov
C++ Developer
CNET dFactory (http://www.cnetdata.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]