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 #ifndef __XBEXCEPT_H__
00043 #define __XBEXCEPT_H__
00044
00045 #ifdef __GNUG__
00046 #pragma interface
00047 #endif
00048
00049 #ifdef __WIN32__
00050 #include <xbase/xbconfigw32.h>
00051 #else
00052 #include <xbase/xbconfig.h>
00053 #endif
00054
00055 #include <xbase/xtypes.h>
00056
00060 const char *xbStrError(xbShort err);
00061
00062 #ifndef HAVE_EXCEPTIONS
00063 #define xb_error(code) { return code;}
00064 #define xb_io_error(code,name) { return code;}
00065 #define xb_open_error(name) { return XB_OPEN_ERROR;}
00066 #define xb_memory_error { return XB_NO_MEMORY;}
00067 #define xb_eof_error { return XB_EOF;}
00068 #else
00069
00070 #ifdef HAVE_EXCEPTION
00071
00072 #include <exception>
00073 #elif HAVE_G___EXCEPTION_H
00074 #include <g++/exception.h>
00075 #elif
00076 #error "Exceptions are unsupported on your system."
00077 #endif
00078
00079 #ifdef __BORLANDC__
00080 #define XB_THROW throw ()
00081 using std::exception;
00082 #else
00083 #define XB_THROW
00084 #endif
00085
00087
00090
00091 class XBDLLEXPORT xbException : public exception {
00092 public:
00093 xbException (int err);
00094 virtual ~xbException () XB_THROW;
00095 virtual const char* what() const XB_THROW;
00096 virtual const char *error();
00097 int getErr();
00098 private:
00099 int err;
00100 };
00101
00102 #define xb_error(code) {throw xbException(code);return (code);}
00103
00105
00108 class XBDLLEXPORT xbIOException : public xbException {
00109 public:
00110 xbIOException (int err);
00111 xbIOException (int err, const char *n);
00112 virtual ~xbIOException () XB_THROW;
00113 virtual const char* what() const XB_THROW;
00114 const char *_errno() const;
00115 const char *name;
00116 protected:
00117 int m_errno;
00118 };
00119
00120 #define xb_io_error(code, name) {throw xbIOException(code,name);return (code);}
00121
00123
00126 class XBDLLEXPORT xbOpenException : public xbIOException {
00127 public:
00128 xbOpenException ();
00129 xbOpenException (const char *n);
00130 virtual ~xbOpenException () XB_THROW;
00131 virtual const char* what() const XB_THROW;
00132 };
00133
00134 #define xb_open_error(name) { throw xbOpenException(name); return 0;}
00135
00137
00140 class XBDLLEXPORT xbOutOfMemoryException : public xbException {
00141 public:
00142 xbOutOfMemoryException ();
00143 virtual ~xbOutOfMemoryException () XB_THROW;
00144 virtual const char* what() const XB_THROW;
00145 };
00146
00147 #define xb_memory_error {throw xbOutOfMemoryException();return 0;}
00148
00150
00153 class XBDLLEXPORT xbEoFException : public xbIOException {
00154 public:
00155 xbEoFException ();
00156 virtual ~xbEoFException () XB_THROW;
00157 virtual const char* what() const XB_THROW;
00158 };
00159
00160 #define xb_eof_error {throw xbEoFException();return 0;}
00161
00162 #endif
00163
00164 #endif // __XBEXCEPT_H__