00001 #ifndef _Error_h_
00002 #define _Error_h_
00003
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <errno.h>
00007
00008 #include <string>
00009
00010 #include "Debug.h"
00011 #include "Logger.h"
00012
00013 #ifndef _ERROR_LOCATION_
00014 #define _ERROR_LOCATION_
00015 #define ERROR_LOCATION __FILE__, __PRETTY_FUNCTION__, __LINE__
00016 #endif
00017
00018
00019
00020
00021
00022
00023
00024
00025 extern Logger slog;
00026
00033 class Error {
00034 public:
00035 string _errtext;
00036 string _file;
00037 string _function;
00038 int _line;
00039 Error(const char *txt = "unknown"):_errtext(txt) {
00040 VERB(slog.p(Logger::Debug);
00041 print());
00042 } Error(const char *txt, const char *file, const char *function,
00043 int line)
00044 :_errtext(txt), _file(file), _function(function), _line(line) {
00045 VERB(slog.p(Logger::Debug);
00046 print());
00047 }
00048 Error(const string & txt):_errtext(txt) {
00049 VERB(slog.p(Logger::Debug);
00050 print());
00051 }
00052 Error(const string & txt, const char *file, const char *function,
00053 int line)
00054 :_errtext(txt), _file(file), _function(function), _line(line) {
00055 VERB(slog.p(Logger::Debug);
00056 print());
00057 }
00058 virtual ~ Error() {
00059 }
00060
00061 virtual void print() {
00062 slog << "Exception!"
00063 << " File: " << _file
00064 << " Function: " << _function
00065 << " Line: " << _line << " Desc: " << _errtext << "\n";
00066 }
00067 };
00068
00075 class SystemError:public Error {
00076 public:
00077 int _errno;
00078 SystemError(const char *txt = "unknown", int errnbr = -1)
00079 :Error(txt), _errno(errnbr) {
00080 } SystemError(const string & txt, int errnbr = -1)
00081 :Error(txt), _errno(errnbr) {
00082 }
00083 SystemError(const char *txt, int errnbr, const char *file,
00084 const char *function, int line)
00085 :Error(txt, file, function, line), _errno(errnbr) {
00086 }
00087 SystemError(const string & txt, int errnbr, const char *file,
00088 const char *function, int line)
00089 :Error(txt, file, function, line), _errno(errnbr) {
00090 }
00091
00092 virtual void print() {
00093 slog << "Exception!"
00094 << " Type: System"
00095 << " File: " << _file
00096 << " Function: " << _function
00097 << " Line: " << _line
00098 << " Desc: " << _errtext
00099 << " ErrStr(" << _errno << "): " << strerror(_errno) <<
00100 "\n";
00101 }
00102 };
00103
00110 class IOError:public SystemError {
00111 public:
00112 IOError(const char *txt = "unknown", int errnbr =
00113 -1):SystemError(txt, errnbr) {
00114 } IOError(const char *txt, int errnbr, const char *file,
00115 const char *function, int line):SystemError(txt, errnbr,
00116 file,
00117 function,
00118 line) {
00119 }
00120 IOError(const string & txt, int errnbr =
00121 -1):SystemError(txt, errnbr) {
00122 }
00123 IOError(const string & txt, int errnbr, const char *file,
00124 const char *function, int line):SystemError(txt, errnbr,
00125 file, function,
00126 line) {
00127 }
00128
00129 virtual void print() {
00130 slog << "Exception!"
00131 << " Type: IO"
00132 << " File: " << _file
00133 << " Function: " << _function
00134 << " Line: " << _line
00135 << " Desc: " << _errtext
00136 << " ErrStr(" << _errno << "): " << strerror(_errno) <<
00137 "\n";
00138 }
00139 };
00140
00147 class AssertionError:public Error {
00148 public:
00149 AssertionError(const char *txt):Error(txt) {
00150 } AssertionError(const char *txt, const char *file,
00151 const char *function, int line):Error(txt, file,
00152 function,
00153 line) {
00154 }
00155 AssertionError(const string & txt):Error(txt) {
00156 }
00157 AssertionError(const string & txt, const char *file,
00158 const char *function, int line):Error(txt, file,
00159 function,
00160 line) {
00161 }
00162
00163 virtual void print() {
00164 slog << "Exception!"
00165 << " Type: Assertion"
00166 << " File: " << _file
00167 << " Function: " << _function
00168 << " Line: " << _line << " Desc: " << _errtext << "\n";
00169 }
00170 };
00171
00172 #endif