00001 00002 // 00003 // Copyright (C) 2000 00004 // Ralf Westram 00005 // Time-stamp: <Sun Nov/24/2002 18:17 MET Coder@ReallySoft.de> 00006 // 00007 // Permission to use, copy, modify, distribute and sell this software 00008 // and its documentation for any purpose is hereby granted without fee, 00009 // provided that the above copyright notice appear in all copies and 00010 // that both that copyright notice and this permission notice appear 00011 // in supporting documentation. Ralf Westram makes no 00012 // representations about the suitability of this software for any 00013 // purpose. It is provided "as is" without express or implied warranty. 00014 // 00015 // This code is part of my library. 00016 // You may find a more recent version at http://www.reallysoft.de/ 00017 // 00019 00020 #ifndef ERR_H 00021 #define ERR_H 00022 00023 #ifndef RS_ASSERT_H 00024 #include <rs_assert.h> 00025 #endif 00026 #ifndef BOOST_UTIL_H 00027 #include <boost_util.h> 00028 #endif 00029 00030 00031 00032 namespace rs { 00033 00041 namespace err { 00042 00044 class Error : public std::runtime_error { 00045 protected: 00046 std::string error_module; 00047 static std::string module_name; 00048 bool real_error; 00049 public: 00055 Error(bool real_error_ /*= true*/, const std::string& s); 00056 00060 Error(const std::string& s); 00061 00065 Error(bool real_error_ /*= true*/, const char *s); 00066 00070 Error(const char *s); 00071 00072 virtual ~Error() throw(); 00073 00077 virtual void print(std::ostream& out) const; 00078 00084 virtual std::string get_print_message() const; 00085 00088 virtual const char *what() const throw() { return runtime_error::what(); } 00089 00092 const char * get_message() const { return what(); } 00093 00097 static std::string set_module_name(const std::string& new_module_name); 00098 00099 friend void reThrow(const exception& e); 00100 }; 00101 00102 /* use this to rethrow an exception that may be an Error. 00103 00104 Error and derived classes are copied and thrown. 00105 Other exceptions are thrown as InternalError */ 00106 void reThrow(const std::exception& e); 00107 00108 // --------------------------------------------------- 00109 // class ErrorModule : rs_boost::noncopyable 00110 // --------------------------------------------------- 00112 class ErrorModule : rs_boost::noncopyable { 00113 private: 00114 std::string old_module_name; 00115 00116 public: 00130 explicit ErrorModule(const std::string& new_module_name, bool appendTo=true) { 00131 old_module_name = Error::set_module_name(new_module_name); 00132 if (appendTo && !old_module_name.empty()) { 00133 Error::set_module_name(old_module_name+"::"+new_module_name); 00134 } 00135 } 00136 ~ErrorModule() { 00137 Error::set_module_name(old_module_name); 00138 } 00139 }; 00140 00141 00142 // -------------------------------------------------------------------------------- 00143 // class InternalError : public Error 00144 // -------------------------------------------------------------------------------- 00146 class InternalError : public Error { 00147 public: 00150 InternalError(const std::string& s) : Error(s) { 00151 #if !defined(FINAL_VERSION) 00152 cerr << "Throwing InternalError(" << s << ")\n"; 00153 #endif // FINAL_VERSION 00154 } 00155 virtual ~InternalError() throw() {} 00156 00163 virtual std::string get_print_message() const; 00164 }; 00165 00166 // -------------------------------------------------------------------------------- 00167 // class IOError : public Error 00168 // -------------------------------------------------------------------------------- 00170 class IOError : public Error { 00171 public: 00178 IOError(const std::string& filename); 00179 00187 IOError(const std::string& filename, const std::string& IO_command); 00188 00189 virtual ~IOError() throw() {} 00190 }; 00191 00192 }; 00193 }; 00194 00195 #else 00196 #error Err.h included twice 00197 #endif // ERR_H
Contact me in case of errors or questions. This documentation is powered by ![]() |
(C) 2000-2002 ![]() |