OpenWalnut
1.4.0
|
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 00032 #include "WTerminalColor.h" 00033 00034 00035 /** 00036 * Basic exception handler. 00037 */ 00038 class WException: public std::exception 00039 { 00040 /** 00041 * Only UnitTests are allowed to be a friend of this class. 00042 */ 00043 friend class WExceptionTest; 00044 00045 public: 00046 /** 00047 * Default constructor. 00048 * \param msg Exception description. 00049 */ 00050 explicit WException( const std::string& msg = std::string() ); 00051 00052 /** 00053 * Copy a std::exception and encapsulate it. 00054 * 00055 * \param e the exception. 00056 */ 00057 explicit WException( const std::exception& e ); 00058 00059 /** 00060 * Destructor. 00061 */ 00062 virtual ~WException() throw(); 00063 00064 /** 00065 * Returns the message string set on throw 00066 * \return Message text 00067 */ 00068 virtual const char* what() const throw(); 00069 00070 /** 00071 * Prints the trace of the call chain which caused this exception. 00072 * \return Calltrace as string 00073 * \note Isn't this useless? Should be removed. 00074 */ 00075 std::string getTrace( ) const; 00076 00077 /** 00078 * Returns a call stacktrace. 00079 * \return The backtrace at the moment of "throw". 00080 */ 00081 std::string getBacktrace() const; 00082 00083 /** 00084 * Function disables backtraces. Please note that the backtrace can not be reactivated to avoid people from dis/enabling them 00085 * at will. 00086 */ 00087 static void disableBacktrace(); 00088 00089 protected: 00090 /** 00091 * Message given during throw. 00092 */ 00093 std::string m_msg; 00094 00095 /** 00096 * Stack trace for identifying the source where this exception came from. 00097 * \note Isn't this useless? Should be removed. 00098 */ 00099 std::list< std::string > m_trace; 00100 00101 /** 00102 * True if the backtrace should NOT be printed. 00103 */ 00104 static bool noBacktrace; 00105 private: 00106 /** 00107 * Color used for the "trace:" label. 00108 */ 00109 WTerminalColor m_labelColor; 00110 00111 /** 00112 * Color used for function name. 00113 */ 00114 WTerminalColor m_functionColor; 00115 00116 /** 00117 * Color used for symbols. 00118 */ 00119 WTerminalColor m_symbolColor; 00120 00121 /** 00122 * Color used for exception headline. 00123 */ 00124 WTerminalColor m_headlineColor; 00125 }; 00126 00127 #endif // WEXCEPTION_H 00128