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, Mar 16, 2001 at 08:00:04AM -0500, nbecker@fred.net wrote:
> As long as we're on the subject, is it possible to make the default
> exception handler do something more useful than just abort?

Inside the language, or outside it?

Inside the language, you can always use std::set_terminate() to call a
user-defined function if a thrown exception tumbles off the top of the
call stack.

Outside the language, you can always edit the libsupc++ files to change
the default behavior, as long as you're willing to live with the results
in your private runtime library.  :-)


> 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.

IIRC, some of the recently-proposed and -applied patches permit enough
information to be retained so that a post-mortem of a coredump caused by
terminate()->abort() can show the call stack and the local variable state
where the exception was thrown.

For that matter, you can always use another solution "inside the language"
along the lines of:

    #define scream_and_choke(m)  \
                    throw std::exception (__FILE__ ":" __LINE__ ":  " m)

        ...
        if (screwup)  scream_and_choke("the frobulator isn't gronkified!");

which will provide the same information in a caught exception's what() fn.


Phil

-- 
pedwards at disaster dot jaj dot com  |  pme at sources dot redhat dot com
devphil at several other less interesting addresses in various dot domains
The gods do not protect fools.  Fools are protected by more capable fools.


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