00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef __XBEXCEPT_H__
00045 #define __XBEXCEPT_H__
00046
00047 #ifdef __GNUG__
00048 #pragma interface
00049 #endif
00050
00051 #ifdef __WIN32__
00052 #include <xbase/xbconfigw32.h>
00053 #else
00054 #include <xbase/xbconfig.h>
00055 #endif
00056
00057 #include <xbase/xtypes.h>
00058
00062 const char *xbStrError(xbShort err);
00063
00064 #ifndef HAVE_EXCEPTIONS
00065 #define xb_error(code) { return code;}
00066 #define xb_io_error(code,name) { return code;}
00067 #define xb_open_error(name) { return XB_OPEN_ERROR;}
00068 #define xb_memory_error { return XB_NO_MEMORY;}
00069 #define xb_eof_error { return XB_EOF;}
00070 #else
00071
00072 #ifdef HAVE_EXCEPTION
00073
00074 #include <exception>
00075 #elif HAVE_G___EXCEPTION_H
00076 #include <g++/exception.h>
00077 #else
00078 #error "Exceptions are unsupported on your system."
00079 #endif
00080
00081 #ifdef __BORLANDC__
00082 #define XB_THROW throw ()
00083 using std::exception;
00084 #else
00085 #define XB_THROW
00086 #endif
00087
00089
00092
00093 class XBDLLEXPORT xbException : public exception {
00094 public:
00095 xbException (int err);
00096 virtual ~xbException () XB_THROW;
00097 virtual const char* what() const XB_THROW;
00098 virtual const char *error();
00099 int getErr();
00100 private:
00101 int err;
00102 };
00103
00104 #define xb_error(code) {throw xbException(code);return (code);}
00105
00107
00110 class XBDLLEXPORT xbIOException : public xbException {
00111 public:
00112 xbIOException (int err);
00113 xbIOException (int err, const char *n);
00114 virtual ~xbIOException () XB_THROW;
00115 virtual const char* what() const XB_THROW;
00116 const char *_errno() const;
00117 const char *name;
00118 protected:
00119 int m_errno;
00120 };
00121
00122 #define xb_io_error(code, name) {throw xbIOException(code,name);return (code);}
00123
00125
00128 class XBDLLEXPORT xbOpenException : public xbIOException {
00129 public:
00130 xbOpenException ();
00131 xbOpenException (const char *n);
00132 virtual ~xbOpenException () XB_THROW;
00133 virtual const char* what() const XB_THROW;
00134 };
00135
00136 #define xb_open_error(name) { throw xbOpenException(name); return 0;}
00137
00139
00142 class XBDLLEXPORT xbOutOfMemoryException : public xbException {
00143 public:
00144 xbOutOfMemoryException ();
00145 virtual ~xbOutOfMemoryException () XB_THROW;
00146 virtual const char* what() const XB_THROW;
00147 };
00148
00149 #define xb_memory_error {throw xbOutOfMemoryException();return 0;}
00150
00152
00155 class XBDLLEXPORT xbEoFException : public xbIOException {
00156 public:
00157 xbEoFException ();
00158 virtual ~xbEoFException () XB_THROW;
00159 virtual const char* what() const XB_THROW;
00160 };
00161
00162 #define xb_eof_error {throw xbEoFException();return 0;}
00163
00164 #endif
00165
00166 #endif // __XBEXCEPT_H__