This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -fno-exceptions documentation


Howard Hinnant wrote:

So for  http://gcc.gnu.org/ml/gcc/2004-10/msg00099.html, my knee-jerk
reaction is to say "recompile libstdc++" with that setting if you
need it to not thrown an exception".  That being said, my response is
probably not what the customer wanted either.  He wanted op new to
return 0 on failure, not abort.  In general it would be nice to give
the customer the ability to customize error handling when exceptions
are turned off.  For example instead of calling abort() in an
exceptional situation we might instead call a weak-linked
__gcc_handle_error(const char* msg).  The customer then might
override this function, inspect the message, and do something that
makes sense for them.  The default implementation could just call
abort(), maybe after printing out the msg.  This still requires a
recompile of libstdc++, but at least it gives the customer another
option.  Here's how it might look:

operator new (std::size_t sz) throw (std::bad_alloc)
{
 ...
      if (! handler)
#ifdef __EXCEPTIONS
throw bad_alloc();
#else
        std::__gcc_handle_error("bad_alloc");
#endif
   ...
}

This is what I do in Boost:


void * operator new (std::size_t sz) throw (std::bad_alloc)
{
   if( !handler )
   {
       boost::throw_exception( std::bad_alloc() );
       return 0;
   }
}

The default boost::throw_exception( x ) throws x, but when exceptions are off, is left undefined for the user to supply an appropriate implementation. In libstdc++, it could have a weak definition that aborts by default.

http://www.boost.org/libs/utility/throw_exception.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]