|
libpsynth 0.2.1
|
00001 00013 /* 00014 * Copyright (C) 2009 Juan Pedro BolĂvar Puente 00015 * 00016 * This file is part of Psychosynth. 00017 * 00018 * Psychosynth is free software: you can redistribute it and/or modify 00019 * it under the terms of the GNU General Public License as published by 00020 * the Free Software Foundation, either version 3 of the License, or 00021 * (at your option) any later version. 00022 * 00023 * Psychosynth is distributed in the hope that it will be useful, 00024 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 * GNU General Public License for more details. 00027 * 00028 * You should have received a copy of the GNU General Public License 00029 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00030 * 00031 */ 00032 00033 00034 #ifndef PSYNTH_EXCEPTION_H_ 00035 #define PSYNTH_EXCEPTION_H_ 00036 00037 #include <exception> 00038 #include <string> 00039 00040 namespace psynth 00041 { 00042 namespace base 00043 { 00044 00048 class exception 00049 { 00050 public: 00051 virtual ~exception () throw () {} 00052 00059 virtual void log () const; 00060 00065 virtual const char* what () const throw () = 0; 00066 00070 virtual const char* where () const throw () = 0; 00071 00075 virtual int level () const throw () = 0; 00076 }; 00077 00082 class error_base : public virtual exception, 00083 public virtual std::exception 00084 { 00085 public: 00087 error_base () 00088 {} 00089 00091 error_base (const std::string& what) 00092 : _what (what) 00093 {} 00094 00095 virtual ~error_base () throw () {} 00096 00097 virtual const char* what () const throw () 00098 { return _what.empty () ? default_what () : _what.c_str (); } 00099 00100 virtual const char* where () const throw () 00101 { return "psynth"; } 00102 00103 virtual int level () const throw (); 00104 00105 protected: 00109 virtual const char* default_what () const throw (); 00110 00111 private: 00112 std::string _what; 00113 }; 00114 00115 int default_error_level () throw (); 00116 00117 #define PSYNTH_DECLARE_ERROR(d_parent, d_error) \ 00118 class d_error : public d_parent \ 00119 { \ 00120 public: \ 00121 typedef d_parent base_type; \ 00122 d_error () {} \ 00123 d_error (const std::string& s) : base_type (s) {} \ 00124 virtual const char* where () const throw (); \ 00125 protected: \ 00126 virtual const char* default_what () const throw (); \ 00127 }; 00128 00129 #define PSYNTH_DEFINE_ERROR_WHERE_WHAT(d_error, d_where, d_what) \ 00130 const char* d_error::where () const throw () \ 00131 { return d_where; } \ 00132 const char* d_error::default_what () const throw () \ 00133 { return d_what; } 00134 00135 #define PSYNTH_DEFINE_ERROR_WHERE(d_error, d_where) \ 00136 const char* d_error::default_what () const throw () \ 00137 { return base_type::default_what (); } \ 00138 const char* d_error::where () const throw () \ 00139 { return d_where; } \ 00140 00141 #define PSYNTH_DEFINE_ERROR_WHAT(d_error, d_what) \ 00142 const char* d_error::default_what () const throw () \ 00143 { return d_what; } \ 00144 const char* d_error::where () const throw () \ 00145 { return PSYNTH_MODULE_NAME; } 00146 00147 #define PSYNTH_DEFINE_ERROR(d_error) \ 00148 const char* d_error::default_what () const throw () \ 00149 { return base_type::default_what (); } \ 00150 const char* d_error::where () const throw () \ 00151 { return PSYNTH_MODULE_NAME; } 00152 00153 PSYNTH_DECLARE_ERROR (error_base, error); 00154 00155 } /* namespace base */ 00156 } /* namespace psynth */ 00157 00158 #endif /* PSYNTH_EXCEPTION_H_ */
1.7.4