This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: exceptions and gdb
- To: Phil Edwards <pedwards at disaster dot jaj dot com>
- Subject: Re: exceptions and gdb
- From: Jeff Sturm <jsturm at one-point dot com>
- Date: Fri, 16 Mar 2001 16:47:54 -0500 (EST)
- cc: nbecker at fred dot net, gcc at gcc dot gnu dot org
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