OpenWalnut 1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WEXCEPTION_H 00026 #define WEXCEPTION_H 00027 00028 #include <exception> 00029 #include <list> 00030 #include <string> 00031 #include <sstream> 00032 00033 #include "WTerminalColor.h" 00034 #include "WExportCommon.h" 00035 00036 /** 00037 * Basic exception handler. 00038 */ 00039 class OWCOMMON_EXPORT WException: public std::exception 00040 { 00041 /** 00042 * Only UnitTests are allowed to be a friend of this class. 00043 */ 00044 friend class WExceptionTest; 00045 00046 public: 00047 00048 /** 00049 * Default constructor. 00050 * \param msg Exception description. 00051 */ 00052 explicit WException( const std::string& msg = std::string() ); 00053 00054 /** 00055 * Copy a std::exception and encapsulate it. 00056 * 00057 * \param e the exception. 00058 */ 00059 explicit WException( const std::exception& e ); 00060 00061 /** 00062 * Destructor. 00063 */ 00064 virtual ~WException() throw(); 00065 00066 /** 00067 * Returns the message string set on throw 00068 * \return Message text 00069 */ 00070 virtual const char* what() const throw(); 00071 00072 /** 00073 * Prints the trace of the call chain which caused this exception. 00074 * \return Calltrace as string 00075 * \note Isn't this useless? Should be removed. 00076 */ 00077 std::string getTrace( ) const; 00078 00079 /** 00080 * Returns a call stacktrace. 00081 * \return The backtrace at the moment of "throw". 00082 */ 00083 std::string getBacktrace() const; 00084 00085 /** 00086 * Function disables backtraces. Please note that the backtrace can not be reactivated to avoid people from dis/enabling them 00087 * at will. 00088 */ 00089 static void disableBacktrace(); 00090 00091 protected: 00092 /** 00093 * Message given during throw. 00094 */ 00095 std::string m_msg; 00096 00097 /** 00098 * Stack trace for identifying the source where this exception came from. 00099 * \note Isn't this useless? Should be removed. 00100 */ 00101 std::list< std::string > m_trace; 00102 00103 /** 00104 * True if the backtrace should NOT be printed. 00105 */ 00106 static bool noBacktrace; 00107 private: 00108 00109 /** 00110 * Color used for the "trace:" label. 00111 */ 00112 WTerminalColor m_labelColor; 00113 00114 /** 00115 * Color used for function name. 00116 */ 00117 WTerminalColor m_functionColor; 00118 00119 /** 00120 * Color used for symbols. 00121 */ 00122 WTerminalColor m_symbolColor; 00123 00124 /** 00125 * Color used for exception headline. 00126 */ 00127 WTerminalColor m_headlineColor; 00128 }; 00129 00130 #endif // WEXCEPTION_H 00131