# vterminate.cc

    00001 // Verbose terminate_handler -*- C++ -*-
    00002
    00003 // Copyright (C) 2001, 2002 Free Software Foundation
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 2, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 #include <cstdlib>
    00031 #include <cstdio>
    00032 #include <exception>
    00033 #include <exception_defines.h>
    00034 #include <cxxabi.h>
    00035
    00036 using namespace std;
    00037 using namespace abi;
    00038
    00039 namespace __gnu_cxx
    00040 {
    00041   /* A replacement for the standard terminate_handler which prints
    00042    more information about the terminating exception (if any) on
    00043    stderr.  */
    00044   void __verbose_terminate_handler()
    00045   {
    00046     // Make sure there was an exception; terminate is also called for an
    00047     // attempt to rethrow when there is no suitable exception.
    00048     type_info *t = __cxa_current_exception_type();
    00049     if (t)
    00050       {
    00051     char const *name = t->name();
    00052     // Note that "name" is the mangled name.
    00053
    00054     {
    00055       int status = -1;
    00056       char *dem = 0;
    00057
    00058       // Disabled until __cxa_demangle gets the runtime GPL exception.
    00059       dem = __cxa_demangle(name, 0, 0, &status);
    00060
    00061       printf("terminate called after throwing a `%s'\n",
    00062          status == 0 ? dem : name);
    00063
    00064       if (status == 0)
    00065         free(dem);
    00066     }
    00067
    00068     // If the exception is derived from std::exception, we can give more
    00069     // information.
    00070     try { __throw_exception_again; }
    00071 #ifdef __EXCEPTIONS
    00072     catch (exception &exc)
    00073       { fprintf(stderr, "  what(): %s\n", exc.what()); }
    00074 #endif
    00075     catch (...) { }
    00076       }
    00077     else
    00078       fprintf(stderr, "terminate called without an active exception\n");
    00079
    00080     abort();
    00081   }
    00082 } // namespace __gnu_cxx