c++/3719: Unable to retrow exception in unexpected exception handler.

Edward Maros efm@localhost.ligo.caltech.edu
Tue Jul 17 14:26:00 GMT 2001


>Number:         3719
>Category:       c++
>Synopsis:       Unable to retrow exception in unexpected exception handler.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 17 14:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Edward Maros
>Release:        3.0
>Organization:
>Environment:
System: Linux localhost 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --prefix=/ldcg/gcc-3.0-toolset --with-local-prefix=/ldcg/gcc-3.0-toolset --with-gnu-ld=/ldcg/gcc-3.0-toolset/bin/ld --with-gnu-as=/ldcg/gcc-3.0-toolset/bin/as --enable-shared --enable-threads=posix
>Description:
When rethrowing an exception from within an exception handler, a segfault occurs.
>How-To-Repeat:
#include <iostream>
#include <stdexcept>


//
// Extended bad_exception class with info on exception no handled in the
// throw specifier
//
class unhandled: public std::bad_exception
{
public:
  unhandled( const std::string& what )
    : m_what( what )
  {
  }

  ~unhandled() throw() {}

  virtual const char*
  what() const throw()
  {
    return m_what.c_str();
  }

private:
  std::string m_what;
};

//
// New handler for unexpected exceptions
//

void
handle_unexpected( void )
{
  try {
    throw;
  }
  catch( std::bad_alloc )
  {
    throw unhandled( "bad_alloc" );
  }
}

//
// No problem
//

void
c1( void ) throw ( std::bad_alloc )
{
  throw std::bad_alloc();
}

//
// No problem
//

void
c2( void )
{
  throw std::bad_alloc();
}

//
// Problem do to bad_alloc not being in throw specification
//

void
c3( void ) throw ( std::bad_exception )
{
  throw std::bad_alloc();
}

main()
{
  std::set_unexpected( handle_unexpected );
  try {
    c1();
  }
  catch ( const std::bad_alloc& e )
  {
    std::cerr << "Caught exception for c1" << std::endl;
  }

  try {
    c2();
  }
  catch ( const std::bad_alloc& e )
  {
    std::cerr << "Caught exception for c2" << std::endl;
  }

  try {
    c3();
  }
  catch ( const std::bad_alloc& e )
  {
    std::cerr << "Caught exception for c3" << std::endl;
  }
  catch ( const std::bad_exception& e )
  {
    std::cerr << "Caught bad_exception for c3" << e.what() << std::endl;
  }

}

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list