Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
XException.h
1// XException.h: interface for the exception classes.
2//
3//////////////////////////////////////////////////////////////////////
4
5#if !defined(CXEXCEPTION_INCLUDE_H)
6#define CXEXCEPTION_INCLUDE_H
7
8#ifdef _MSC_VER
9#pragma once
10#endif // _MSC_VER
11
12#include "XObject.h"
13
14BEGIN_MOOTOOLS_NAMESPACE
15
16 ///////////////////////////////////////////////////////////////////////
17 // Exceptions helpers
18 class CXException;
19
20 DLL_TOOLSFUNCTION void XSetThreadException(CXException *ex);
21 DLL_TOOLSFUNCTION void XDeleteThreadException();
22
23 ///////////////////////////////////////////////////////////////////////
24 // Exceptions classes
25
26 class DLL_TOOLSFUNCTION CXException : public CXObject
27 {
28 DECLARE_DYNAMIC_XOBJECT(CXException)
29
30 public:
31 CXException(const CXString& txt = CXString());
32 virtual ~CXException();
33 void Delete();
34
35 CXString GetErrorMessage() const;
36
37 virtual bool ReportError(unsigned int nMessageID = 0);
38
39 protected:
40 CXString exceptionTxt;
41 };
42
43 class DLL_TOOLSFUNCTION CXFileException : public CXException
44 {
45 DECLARE_DYNAMIC_XOBJECT(CXFileException)
46
47 public:
48 typedef enum FileExceptionType {
49 none,
50 genericException,
51 fileNotFound,
52 badPath,
53 tooManyOpenFiles,
54 accessDenied,
55 invalidFile,
56 removeCurrentDir,
57 directoryFull,
58 badSeek,
59 hardIO,
60 sharingViolation,
61 lockViolation,
62 diskFull,
63 endOfFile,
64 } FileExceptionType;
65
66 // Constructor
67 CXFileException(FileExceptionType error = none, const CXString& filename = CXString(), const CXString& exceptiontxt = CXString());
68
69 // Attributes
70 FileExceptionType cause;
71 CXString filename;
72
73 static FileExceptionType ErrnoToException(int nErrno);
74 static void ThrowOsError(FileExceptionType defaultType, const CXString& filename, CXFileException *e = NULL); // Set a default exception type, that might be internally overidden by an OS error code to get more precise information
75 static void ThrowErrno(FileExceptionType error, int nErrno, const CXString& filename, CXFileException *e = NULL); // Set a stdlib error code
76
77 // Implementation
78 public:
79 virtual CXString GetErrorMessage() const;
80
81 #ifdef _DEBUG
82 void IsXException() {}; // Only to check we really have a
83 virtual void Dump() const;
84 #endif
85 };
86
87
88 class DLL_TOOLSFUNCTION CXArchiveException : public CXException
89 {
90 DECLARE_DYNAMIC_XOBJECT(CXArchiveException)
91
92 public:
93 typedef enum ArchiveExceptionType {
94 none,
95 genericException,
96 readOnly,
97 endOfFile,
98 writeOnly,
99 badIndex,
100 badClass,
101 badSchema,
102 bufferFull
103 } ArchiveExceptionType;
104
105 // Constructor
106 CXArchiveException(ArchiveExceptionType error = none, const CXString& filename = CXString());
107
108 // Attributes
109 int cause;
110 CXString filename;
111
112 // Implementation
113 public:
114 virtual CXString GetErrorMessage() const;
115
116 #ifdef _DEBUG
117 virtual void Dump() const;
118 #endif
119 };
120
121 class DLL_TOOLSFUNCTION CXUserException : public CXException // general user visible alert
122 {
123 DECLARE_DYNAMIC_XOBJECT(CXUserException)
124 };
125
126 class DLL_TOOLSFUNCTION CXMemoryException : public CXException // out-of-memory exception
127 {
128 DECLARE_DYNAMIC_XOBJECT(CXMemoryException)
129 };
130
131 class DLL_TOOLSFUNCTION CXInvalidArgException : public CXException // one of the parameters to the function is invalid
132 {
133 DECLARE_DYNAMIC_XOBJECT(CXInvalidArgException)
134 };
135
136
137 class DLL_TOOLSFUNCTION CXInternetException : public CXException
138 {
139 DECLARE_DYNAMIC_XOBJECT(CXInternetException)
140
141 public:
142 typedef enum InternetExceptionType {
143 none,
144 genericException,
145 } InternetExceptionType;
146
147 // Constructor
148 CXInternetException(longuint context, unsigned int error = 0);
149
150 // Attributes
151 unsigned int cause;
152 longuint context;
153
154 // Implementation
155 public:
156 virtual CXString GetErrorMessage(unsigned int *pnHelpContext = NULL) const;
157
158 #ifdef _DEBUG
159 virtual void Dump() const;
160 #endif
161 };
162
163#define XThrowException(exception) \
164 { \
165 XTRACE(_T("Warning: throwing exception of type %s\n"), _T(#exception)); \
166 exception *ex = xNew(exception); \
167 XSetThreadException(ex); \
168 throw ex; \
169 }
170
171#define XThrowExceptionWithArgs(exception, ...) \
172 { \
173 XTRACE(_T("Warning: throwing exception of type %s\n"), _T(#exception)); \
174 exception *ex = xNewParams(exception, __VA_ARGS__); \
175 XSetThreadException(ex); \
176 throw ex; \
177 }
178
179#define XENSURE(cond) \
180 { \
181 if (!(cond)) \
182 XThrowException(CXInvalidArgException) \
183 }
184
185#define XTHROW_LAST() throw
186
187#define XTRY \
188 { \
189 try \
190 {
191
192#define XCATCH(class, e) \
193 } \
194 catch (class *e) \
195 { \
196 XASSERT(e->IsKindOf(XRUNTIME_CLASS(CXException)));
197
198#define XCATCH_ALL \
199 } \
200 catch (...) \
201 { \
202
203#define XEND_CATCH \
204 } \
205 XDeleteThreadException(); \
206 }
207
208END_MOOTOOLS_NAMESPACE
209
210#endif // !defined(CXEXCEPTION_INCLUDE_H)
CXTString< TCHAR > CXString
CXString depend on the target OS. Could be CXStringW (Windows) or CXStringA (Linux / Macos)
Definition XString.h:118
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition XException.h:27
Definition XException.h:122