src/tool/error.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program 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
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Refresh des erreurs, exceptions, assertions, etc.
00020  *****************************************************************************/
00021 
00022 #include "../include/base.h"
00023 #include <iostream>
00024 #include <signal.h>
00025 #include "../tool/i18n.h"
00026 
00027 #if !defined WIN32 || defined __MINGW32__
00028 #include <sys/types.h>
00029 #include <unistd.h>
00030 #endif
00031 
00032 void WakeUpDebugger()
00033 {
00034 
00035 #ifdef LOVE_HAYPO_HACKS
00036   // Generate SIGTRAP
00037   asm ("int $0x03");
00038 #endif
00039     
00040 #if !defined WIN32
00041   kill (getpid(), SIGABRT);
00042 #endif
00043 }
00044 
00045 void MissedAssertion (const char *filename, unsigned long line,
00046                        const char *message)
00047 {
00048   std::cout << std::endl;
00049   std::cerr << filename << ':' << line 
00050             << ": Missed assertion \"" << message << "\"."
00051             << std::endl;
00052 #if defined DEBUG
00053   WakeUpDebugger();
00054   abort();
00055 #endif
00056 }
00057 
00058 CError::CError (const char *filename, unsigned long line, 
00059                 const std::string &txt) 
00060   : m_filename(filename), m_txt(txt), m_line(line)
00061 {}
00062 
00063 CError::~CError() throw()
00064 {}
00065 
00066 const char* CError::what() const throw()
00067 {
00068   return m_txt.c_str();
00069 }
00070 
00071 std::ostream& CError::operator<< (std::ostream &os) const
00072 {
00073   os << m_txt;
00074   return os;
00075 }
00076 
00077 void TriggerError (const char *filename, unsigned long line, 
00078                       const std::string &txt)
00079 {
00080   std::cout << "! " 
00081             << Format(_("Error in %s:%lu"), filename, line)
00082             << ": " << txt << std::endl;
00083 
00084   assert(false);
00085   throw CError (filename, line, txt);
00086 }

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7