// -*-c++-*- //------------------------------------------------------------------------------ // xword - (http://xword.sourceforge.net) // Copyright 2002 Patrick Crosby //------------------------------------------------------------------------------ // ErrorManager.cpp // // $Id: ErrorManager.cpp,v 1.2 2002/01/23 19:43:03 pcrosby Exp $ //------------------------------------------------------------------------------ // This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software // Foundation; either version 2 of the License, or (at your option) any later // version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // details. // // You should have received a copy of the GNU General Public License along with // this program; if not, write to the Free Software Foundation, Inc., 59 Temple // Place, Suite 330, Boston, MA 02111-1307 USA //------------------------------------------------------------------------------ #include "ErrorManager.h" #ifdef HAVE_EXECINFO_H #include #endif #include "ErrorDialog.h" #include "Log.h" #include "Namespace.h" NAMESPACE_OPEN //------------------------------------------------------------------------------ ErrorManager* ErrorManager::s_pInstance = NULL; //------------------------------------------------------------------------------ ErrorManager::ErrorManager() { } //------------------------------------------------------------------------------ ErrorManager* ErrorManager::I() { if (s_pInstance == NULL) { s_pInstance = new ErrorManager; } return s_pInstance; } //------------------------------------------------------------------------------ void ErrorManager::Noise(const std::string& strMessage) const { Log::Noise(strMessage); } //------------------------------------------------------------------------------ void ErrorManager::Trace(const std::string& strMessage) const { Log::Trace(strMessage); } //------------------------------------------------------------------------------ void ErrorManager::Warn(const std::string& strMessage) const { Log::Warn(strMessage); } //------------------------------------------------------------------------------ void ErrorManager::Error(const std::string& strMessage) const { Log::Error(strMessage); } //------------------------------------------------------------------------------ void ErrorManager::SetLogLevel(LogLevel nLevel) { Log::SetLevel((Log::LogLevel)nLevel); } //------------------------------------------------------------------------------ void ErrorManager::Dialog(const std::string& strMessage) { Error(strMessage); ErrorDialog::Instance()->SetText(strMessage); ErrorDialog::Instance()->CenterOverDisplay(); ErrorDialog::Instance()->show_all(); } //------------------------------------------------------------------------------ void ErrorManager::BackTrace() const { #ifdef HAVE_EXECINFO_H void* buf[10]; int count = backtrace(buf, 10); char** s = backtrace_symbols(buf, count); for (int i = 0; i < count; i++) { Error(s[i]); } #else Error("no backtrace function available"); #endif } //------------------------------------------------------------------------------ file_error::file_error(const std::string& str) : runtime_error(str) { EM::I()->BackTrace(); } //------------------------------------------------------------------------------ NAMESPACE_CLOSE //------------------------------------------------------------------------------