00001 /*************************************************************************** 00002 LOW_exception.h - description 00003 ------------------- 00004 begin : Sat Jul 6 2002 00005 copyright : (C) 2002 by Harald Roelle 00006 email : roelle@informatik.uni-muenchen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LOW_EXCEPTION_H 00019 #define LOW_EXCEPTION_H 00020 00021 00022 #include <string> 00023 00024 #include "LOW_platformMiscFactory.h" 00025 #include "LOW_objectSynchronizerMacros.h" 00026 00027 class LOW_thread_rwlock; 00028 00029 00030 /** Macro for easy subclassing of LOW_exception. 00031 */ 00032 #define class_DERIVE_FROM_EXCEPTION(DERIVED,SUPER) \ 00033 class DERIVED : public SUPER { \ 00034 public: DERIVED( const std::string inMsg, const std::string inFile, const int inLine) : SUPER( inMsg, inFile, inLine) {}; \ 00035 DERIVED( const int inErrNum, const std::string inMsg, const std::string inFile, const int inLine) : SUPER( inErrNum, inMsg, inFile, inLine) {}; \ 00036 } 00037 00038 00039 00040 /** Base class for all exception of this library. 00041 00042 This class is thread-safe. 00043 00044 @author Harald Roelle 00045 */ 00046 class LOW_exception { 00047 00048 //======================================================================================= 00049 public: 00050 00051 //===================================================================================== 00052 // 00053 // attributes 00054 // 00055 00056 const int errNum; /**< OS error number. */ 00057 const std::string message; /**< Descriptive message. */ 00058 const std::string file; /**< File from which exception was thrown. */ 00059 const int line; /**< Line number where exception was thrown. */ 00060 00061 00062 //===================================================================================== 00063 // 00064 // constructors 00065 // 00066 00067 /** Default constructor. 00068 */ 00069 LOW_exception(); 00070 00071 /** Constructor. 00072 @param inMsg Message describing the exception. 00073 @param inFile File from which exception is thrown. 00074 @param inLine Line number where exception is thrown. 00075 */ 00076 LOW_exception( const std::string inMsg, const std::string inFile, const int inLine); 00077 00078 /** Constructor for OS errors. 00079 00080 The textual OS description (perror) is added automatically when exception is logged. 00081 00082 @param inErrNum OS error number. 00083 @param inMsg Message describing the exception. 00084 @param inFile File from which exception is thrown. 00085 @param inLine Line number where exception is thrown. 00086 */ 00087 LOW_exception( const int inErrNum, const std::string inMsg, const std::string inFile, const int inLine); 00088 00089 /** Destructor. 00090 */ 00091 virtual ~LOW_exception(); 00092 00093 00094 //===================================================================================== 00095 // 00096 // static methods 00097 // 00098 00099 /** Set wether exceptions should be logged automatically when created. 00100 @param inLogOnCreation Wether exceptions should be logged automatically. 00101 */ 00102 static void setLogOnCreation( const bool inLogOnCreation); 00103 00104 /** Get wether exceptions are logged automatically when created. 00105 @return Wether exceptions are logged automatically. 00106 */ 00107 static const bool getLogOnCreation(); 00108 00109 00110 //===================================================================================== 00111 // 00112 // methods 00113 // 00114 00115 /** Log the exception via LOW_helper_msglog::printError() 00116 @param inPrefix Prefix to prepend to the log message. 00117 */ 00118 virtual void logException( const std::string inPrefix = ""); 00119 00120 00121 //======================================================================================= 00122 protected: 00123 00124 //===================================================================================== 00125 // 00126 // static attributes 00127 // 00128 00129 __LOW_SYNCHRONIZE_DEFINE_PROTECTED_LOCK__ 00130 00131 /** Indicates wether exception should be logged automatically when the are created. */ 00132 static bool logOnCreation; 00133 00134 }; 00135 00136 #endif