00001 ///////////////////////////////////////////////////////////////////////////////////////// 00002 /// \file exceptions.h 00003 /// \brief Declaration of the generic exception classes used in the %SPARK solver 00004 /// 00005 /// \li class SPARK::XAssertion 00006 /// \li class SPARK::XDimension 00007 /// \li class SPARK::XOutOfRange 00008 /// \li class SPARK::XMemory 00009 /// \li class SPARK::XInitialization 00010 /// \li class SPARK::XIO 00011 /// \li class SPARK::XTimeStep 00012 /// \li class SPARK::XStepper 00013 /// 00014 ///////////////////////////////////////////////////////////////////////////////////////// 00015 /// \attention 00016 /// PORTIONS COPYRIGHT (C) 2003 AYRES SOWELL ASSOCIATES, INC. \n 00017 /// PORTIONS COPYRIGHT (C) 2003 THE REGENTS OF THE UNIVERSITY OF CALIFORNIA . 00018 /// PENDING APPROVAL BY THE US DEPARTMENT OF ENERGY. ALL RIGHTS RESERVED. 00019 /// 00020 ///////////////////////////////////////////////////////////////////////////////////////// 00021 /// \author Dimitri Curtil (LBNL/SRG) 00022 /// \date September 5, 2002 00023 ///////////////////////////////////////////////////////////////////////////////////////// 00024 00025 00026 00027 #if !defined(__EXCEPTIONS_H__) 00028 #define __EXCEPTIONS_H__ 00029 00030 00031 // Gets rid of warning messages about dll-interface for private data member 00032 // Message shows typically with std classes, e.g., std::string, std::exception, ... 00033 #pragma warning(disable:4251) 00034 #pragma warning(disable:4275) 00035 00036 00037 #include <exception> 00038 #include <stdexcept> 00039 #include <string> 00040 00041 #include "compat.h" // macro CLASS_DECLSPEC 00042 #include "exitcode.h" // for enum ExitCodes 00043 00044 00045 ///////////////////////////////////////////////////////////////////////////////////////// 00046 /// \namespace SPARK 00047 /// 00048 /// \brief Definition of the %SPARK generic exception classes 00049 ///////////////////////////////////////////////////////////////////////////////////////// 00050 00051 namespace SPARK { 00052 00053 00054 ///////////////////////////////////////////////////////////////////////////////////// 00055 /// \class XAssertion 00056 /// \brief Base class for all %SPARK exceptions 00057 class CLASS_DECLSPEC XAssertion : public std::exception 00058 { 00059 public: 00060 ///////////////////////////////////////////////////////////////////////////////// 00061 // Type definition 00062 ///////////////////////////////////////////////////////////////////////////////// 00063 00064 /// Locally rename ExitCodes as TCode 00065 typedef enum ExitCodes TCode; 00066 00067 00068 ///////////////////////////////////////////////////////////////////////////////// 00069 // Structors 00070 ///////////////////////////////////////////////////////////////////////////////// 00071 00072 /// Constructor with message specified as std::string 00073 XAssertion(const std::string& type, const std::string& where, const std::string& message, TCode code) 00074 : Type(type), Where(where), Message(message), Code(code) 00075 {} 00076 /// Copy constructor 00077 XAssertion(const XAssertion& x) 00078 : Type(x.Type), Where(x.Where), Message(x.Message), Code(x.Code), std::exception(x) 00079 {} 00080 /// Trivial destructor 00081 virtual ~XAssertion() SPARK_NOT_THROWING 00082 {} 00083 00084 00085 ///////////////////////////////////////////////////////////////////////////////// 00086 // Access methods 00087 ///////////////////////////////////////////////////////////////////////////////// 00088 00089 /// Returns a description of the exception as a const char* 00090 virtual const char* what() const SPARK_NOT_THROWING; 00091 00092 /// Returns type of the exception as const char* 00093 const char* type() const SPARK_NOT_THROWING { return Type.c_str(); } 00094 00095 /// Returns message associated with the exception as const char* 00096 const char* message() const SPARK_NOT_THROWING { return Message.c_str(); } 00097 00098 /// Returns where the exception was thrown from as const char* 00099 const char* where() const SPARK_NOT_THROWING { return Where.c_str(); } 00100 00101 /// Returns code of the exception as TCode 00102 TCode code() const SPARK_NOT_THROWING { return Code; } 00103 00104 00105 ///////////////////////////////////////////////////////////////////////////////// 00106 // Trace methods 00107 ///////////////////////////////////////////////////////////////////////////////// 00108 00109 /// Appends sender's information to Where string following " <- " 00110 XAssertion& operator[](const std::string& where); 00111 00112 /// Appends msg to Message string on a new line 00113 XAssertion& operator()(const std::string& msg); 00114 00115 00116 private: 00117 ///////////////////////////////////////////////////////////////////////////////// 00118 XAssertion(); // no default constructor 00119 XAssertion& operator=(const XAssertion& x); // no assignment operation 00120 00121 ///////////////////////////////////////////////////////////////////////////////// 00122 // Private data 00123 ///////////////////////////////////////////////////////////////////////////////// 00124 TCode Code; 00125 const std::string Type; 00126 std::string Message; 00127 std::string Where; 00128 }; 00129 ///////////////////////////////////////////////////////////////////////////////////// 00130 00131 00132 //////////////////////// 00133 // Generic exceptions // 00134 //////////////////////// 00135 00136 ///////////////////////////////////////////////////////////////////////////////////// 00137 /// \class XDimension 00138 /// \brief Indicates that a runtime error occured due to mismatched dimension 00139 class CLASS_DECLSPEC XDimension : public XAssertion 00140 { 00141 public: 00142 /// \brief Constructor 00143 /// \param where string specified as <code>const std::string&</code> indicating where in the source code this exception is thrown from 00144 /// \param message string specified as <code>const std::string&</code> documenting the reason for throwing this exception 00145 XDimension(const std::string& where, const std::string& message) 00146 : XAssertion("Dimension exeption", where, message, ExitCode_ERROR_RUNTIME_ERROR) 00147 {} 00148 }; 00149 ///////////////////////////////////////////////////////////////////////////////////// 00150 00151 00152 ///////////////////////////////////////////////////////////////////////////////////// 00153 /// \class XOutOfRange 00154 /// \brief Indicates that a runtime error occured due to an out of range access 00155 /// operation on a container 00156 class CLASS_DECLSPEC XOutOfRange : public XAssertion 00157 { 00158 public: 00159 /// \brief Constructor 00160 /// \param where string specified as <code>const std::string&</code> indicating where in the source code this exception is thrown from 00161 /// \param message string specified as <code>const std::string&</code> documenting the reason for throwing this exception 00162 XOutOfRange(const std::string& where, const std::string& message) 00163 : XAssertion("Out-of-range exception", where, message, ExitCode_ERROR_RUNTIME_ERROR) 00164 {} 00165 }; 00166 ///////////////////////////////////////////////////////////////////////////////////// 00167 00168 00169 ///////////////////////////////////////////////////////////////////////////////////// 00170 /// \class XMemory 00171 /// \brief Indicates that a runtime error occured because memory could not be allocated 00172 class CLASS_DECLSPEC XMemory : public XAssertion 00173 { 00174 public: 00175 /// \brief Constructor 00176 /// \param where string specified as <code>const std::string&</code> indicating where in the source code this exception is thrown from 00177 /// \param message string specified as <code>const std::string&</code> documenting the reason for throwing this exception 00178 XMemory(const std::string& where, const std::string& message) 00179 : XAssertion("Memory exception", where, message, ExitCode_ERROR_OUT_OF_MEMORY) 00180 {} 00181 }; 00182 ///////////////////////////////////////////////////////////////////////////////////// 00183 00184 00185 ///////////////////////////////////////////////////////////////////////////////////// 00186 /// \class XInitialization 00187 /// \brief Indicates that a runtime error occured while initializing an object 00188 class CLASS_DECLSPEC XInitialization : public XAssertion 00189 { 00190 public: 00191 /// \brief Constructor 00192 /// \param where string specified as <code>const std::string&</code> indicating where in the source code this exception is thrown from 00193 /// \param message string specified as <code>const std::string&</code> documenting the reason for throwing this exception 00194 /// \param code ExitCodes used to qualify the type of initilazation exception 00195 XInitialization(const std::string& where, const std::string& message, TCode code) 00196 : XAssertion("Initialization exception", where, message, code) 00197 {} 00198 }; 00199 ///////////////////////////////////////////////////////////////////////////////////// 00200 00201 00202 ///////////////////////////////////////////////////////////////////////////////////// 00203 /// \class XIO 00204 /// \brief Indicates that a runtime error occured while performing an IO operation 00205 class CLASS_DECLSPEC XIO : public XAssertion 00206 { 00207 public: 00208 /// \brief Constructor 00209 /// \param where string specified as <code>const std::string&</code> indicating where in the source code this exception is thrown from 00210 /// \param message string specified as <code>const std::string&</code> documenting the reason for throwing this exception 00211 XIO(const std::string& where, const std::string& message) 00212 : XAssertion("IO exception", where, message, ExitCode_ERROR_IO) 00213 {} 00214 }; 00215 ///////////////////////////////////////////////////////////////////////////////////// 00216 00217 00218 ///////////////////////////////////////////////////////////////////////////////////// 00219 /// \class XTimeStep 00220 /// \brief Indicates that a runtime error occured while adapting the time step 00221 class CLASS_DECLSPEC XTimeStep : public XAssertion 00222 { 00223 public: 00224 /// \brief Constructor 00225 /// \param where string specified as <code>const std::string&</code> indicating where in the source code this exception is thrown from 00226 /// \param message string specified as <code>const std::string&</code> documenting the reason for throwing this exception 00227 XTimeStep(const std::string& where, const std::string& message) 00228 : XAssertion("Time step exception", where, message, ExitCode_ERROR_NUMERICAL) 00229 {} 00230 }; 00231 ///////////////////////////////////////////////////////////////////////////////////// 00232 00233 00234 ///////////////////////////////////////////////////////////////////////////////////// 00235 /// \class XStepper 00236 /// \brief Inidicates that stepping to the next step failed. 00237 class CLASS_DECLSPEC XStepper : public XAssertion 00238 { 00239 public: 00240 /// \brief Constructor 00241 /// \param where string specified as <code>const std::string&</code> indicating where in the source code this exception is thrown from 00242 /// \param message string specified as <code>const std::string&</code> documenting the reason for throwing this exception 00243 XStepper(const std::string& where, const std::string& message) 00244 : XAssertion("Stepper exception", where, message, ExitCode_ERROR_RUNTIME_ERROR) 00245 {} 00246 }; 00247 ///////////////////////////////////////////////////////////////////////////////////// 00248 00249 00250 }; // namespace SPARK 00251 ///////////////////////////////////////////////////////////////////////////////////////// 00252 00253 00254 #endif //__EXCEPTIONS_H__ 00255