00001 // Copyright (C) 2004, Kenneth C. Schalk 00002 00003 // This file is part of Vesta. 00004 00005 // Vesta is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 00010 // Vesta is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with Vesta; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 // Last modified on Tue Sep 14 14:51:22 EDT 2004 by ken@xorian.net 00020 00021 // ---------------------------------------------------------------------- 00022 // This file defines replacement for the "unexpected" and "terminate" 00023 // handlers which are part of the C++ exception handling system. 00024 // Unlike the default handlers, these print an informative message 00025 // before aborting, which at least makes it slightly easier to 00026 // determine what happened. 00027 // ---------------------------------------------------------------------- 00028 00029 #include <stdlib.h> 00030 #include <exception> 00031 #include <iostream> 00032 00033 using std::cerr; 00034 using std::endl; 00035 using std::set_unexpected; 00036 using std::set_terminate; 00037 00038 static void verbose_unexpected() 00039 { 00040 // We try to use as few calls to the stream library as possible, as 00041 // we don't know what state the run-time is in overall. 00042 static char *msg = 00043 "FATAL ERROR: unexpected exception handler called; program will\n" 00044 "exit with a core dump\n\n" 00045 "This is almost certainly a bug. Please report it.\n"; 00046 cerr << msg; 00047 cerr.flush(); 00048 00049 // And we're outta here. 00050 abort(); 00051 } 00052 00053 static void verbose_terminate() 00054 { 00055 static char *msg = 00056 "FATAL ERROR: exception terminate handler called; program will\n" 00057 "exit with a core dump\n\n" 00058 "This is almost certainly a bug. Please report it.\n"; 00059 cerr << msg; 00060 cerr.flush(); 00061 00062 // And we're outta here. 00063 abort(); 00064 } 00065 00066 // Use a static class instance to set the handlers before the prgoram 00067 // starts. 00068 class handler_setter 00069 { 00070 public: 00071 handler_setter() 00072 { 00073 set_unexpected(verbose_unexpected); 00074 set_terminate(verbose_terminate); 00075 } 00076 }; 00077 handler_setter my_handler_setter;