escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 #ifndef ESYSEXCEPTION_H 00019 #define ESYSEXCEPTION_H 00020 #include "system_dep.h" 00021 00022 #include <string> 00023 #include <exception> 00024 #include <iostream> 00025 00026 namespace esysUtils 00027 { 00031 class EsysException : public std::exception 00032 { 00033 00034 protected: 00035 00036 typedef std::exception Parent; 00037 00038 00039 public: 00044 ESYSUTILS_DLL_API 00045 EsysException(); 00046 00053 ESYSUTILS_DLL_API 00054 EsysException(const std::string &exceptionReason); 00055 00062 ESYSUTILS_DLL_API 00063 EsysException( const char *cStr ); 00064 00071 ESYSUTILS_DLL_API 00072 EsysException(const EsysException &other); 00073 00075 ESYSUTILS_DLL_API 00076 virtual ~EsysException() THROW(NO_ARG); 00077 00087 ESYSUTILS_DLL_API 00088 EsysException & 00089 operator=(const EsysException &other) THROW(NO_ARG); 00090 00098 inline 00099 const std::string & toString() const; 00100 00108 ESYSUTILS_DLL_API 00109 virtual const std::string & exceptionName() const; 00110 00117 inline 00118 const std::string& reason() const; 00119 00126 inline 00127 void setReason(const std::string &new_reason); 00128 00136 ESYSUTILS_DLL_API 00137 inline 00138 virtual const char* what() const THROW(NO_ARG); 00139 00140 00145 inline 00146 void updateMessage(); 00147 00148 00149 private: 00150 // 00151 // the exception reason 00152 std::string m_reason; 00153 00154 // 00155 // the full exception message 00156 std::string m_exceptionMessage; 00157 00158 // 00159 // the exception name is immutable and class-wide. 00160 // Inheritor note; you need one of these too. 00161 // and an overloaded exceptionName() in your .cpp implementation file. 00162 static const std::string exceptionNameValue; 00163 00164 }; 00165 00174 ESYSUTILS_DLL_API 00175 std::ostream &operator<<(std::ostream &output, EsysException &inException); 00176 00177 00179 00180 const std::string & EsysException::reason() const 00181 { 00182 return m_reason; 00183 } 00184 00185 // return the message as a std::string 00186 const std::string & EsysException::toString() const 00187 { 00188 return m_exceptionMessage; 00189 } 00190 00191 void EsysException::setReason(const std::string &new_reason) 00192 { 00193 m_reason = new_reason; 00194 updateMessage(); 00195 } 00196 00197 const char* EsysException::what() const THROW(NO_ARG) 00198 { 00199 return m_exceptionMessage.c_str(); 00200 } 00201 00202 void EsysException::updateMessage() 00203 { 00204 m_exceptionMessage = exceptionName() + ": " + m_reason; 00205 } 00206 00207 } 00208 00209 #endif