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


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

Re: exceptions and gdb




On Fri, 16 Mar 2001, Phil Edwards wrote:
> > One possible use for exceptions as an alternative to C assert.  As it
> > is now, it's not a very attractive alternative.  assert will tell me
> > the file, line, and test that failed.  throw tells me nothing.
> 
> Exceptions can't really replace assertions.  The context of the assert()
> is the function in which it's called.  In contrast, exceptions unwind the
> call stack.

In java we sometimes use exceptions that way (there is no assert facility
in the language).  The gcj runtime creates a default handler per thread
for uncaught exceptions.  This handler prints a stack trace and aborts the
thread.  Unwinding the stack is important for cleanup, especially if the
program is to continue.

A stack trace is generated via backtrace() when a throwable object is
thrown, then stored for later use.  One could adopt this convention for
C++ exception handling if desired.

Jeff



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