JWS C++ Library
C++ language utility library
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00046 #ifndef EXCEPTION_H 00047 #define EXCEPTION_H 00048 00049 00050 #include <jwsc++/config.h> 00051 00052 #include <cstdlib> 00053 #include <cstdio> 00054 #include <string> 00055 #include <iostream> 00056 00057 #include <inttypes.h> 00058 00059 00060 using std::string; 00061 using std::ostream; 00062 using std::cerr; 00063 00064 00065 namespace jwscxx { 00066 namespace base { 00067 00068 00074 class Exception 00075 { 00076 public: 00077 00079 Exception(const char* msg, const char* file=0, uint32_t line=0); 00080 00081 00083 Exception(const string& msg, const char* file=0, uint32_t line=0); 00084 00085 00087 Exception(const Exception& e); 00088 00089 00091 virtual ~Exception() { } 00092 00093 00095 const string& get_msg() const { return msg; } 00096 00097 00099 const char* get_file() const { return file; } 00100 00101 00103 uint32_t get_line() const { return line; } 00104 00105 00107 virtual void print(ostream& out=cerr, bool newline=true) const; 00108 00109 00111 virtual void print_details(ostream& out=cerr, bool newline=true) const; 00112 00113 00115 virtual void print_abort(ostream& out=cerr, bool newline=true) const; 00116 00117 00122 virtual void print_details_abort 00123 ( 00124 ostream& out = cerr, 00125 bool newline = true 00126 ) 00127 const; 00128 00129 00131 virtual void print_exit 00132 ( 00133 ostream& out = cerr, 00134 bool newline = true, 00135 int status = EXIT_FAILURE 00136 ) 00137 const; 00138 00139 00144 virtual void print_details_exit 00145 ( 00146 ostream& out = cerr, 00147 bool newline = true, 00148 int status = EXIT_FAILURE 00149 ) 00150 const; 00151 00152 00153 protected: 00154 00156 string msg; 00157 00159 const char* file; 00160 00162 uint32_t line; 00163 }; 00164 00165 00166 00167 00173 class IO_error : public Exception 00174 { 00175 public: 00176 00178 IO_error(const char* msg, const char* file=0, uint32_t line=0); 00179 00180 00182 IO_error(const string& msg, const char* file=0, uint32_t line=0); 00183 00184 00186 IO_error(const IO_error& e); 00187 00188 00190 virtual ~IO_error() { } 00191 }; 00192 00193 00194 00195 00203 class Arg_error : public Exception 00204 { 00205 public: 00206 00211 Arg_error(const char* msg, const char* file=0, uint32_t line=0); 00212 00213 00218 Arg_error(const string& msg, const char* file=0, uint32_t line=0); 00219 00220 00222 Arg_error(const Arg_error& e); 00223 00224 00226 virtual ~Arg_error() { } 00227 }; 00228 00229 00230 00231 00239 class Result_error : public Exception 00240 { 00241 public: 00242 00247 Result_error(const char* msg, const char* file=0, uint32_t line=0); 00248 00249 00254 Result_error(const string& msg, const char* file=0, uint32_t line=0); 00255 00256 00258 Result_error(const Result_error& e); 00259 00260 00262 virtual ~Result_error() { } 00263 }; 00264 00265 00266 }} 00267 00268 00269 #endif