aboutsummaryrefslogtreecommitdiff
path: root/src/exceptionbase.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/exceptionbase.h')
-rw-r--r--src/exceptionbase.h190
1 files changed, 0 insertions, 190 deletions
diff --git a/src/exceptionbase.h b/src/exceptionbase.h
deleted file mode 100644
index b6ad9ca..0000000
--- a/src/exceptionbase.h
+++ /dev/null
@@ -1,190 +0,0 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_EXCEPTION_BASE_H
9#define BU_EXCEPTION_BASE_H
10
11#include <exception>
12#include <stdarg.h>
13
14// This shouldn't normally be defined here, I don't think it's all that portable
15// and it also changes the class interface, we should find out how much of
16// an issue that is, we could just put in an empty getBacktrace() function for
17// when you don't have support for it...
18
19namespace Bu
20{
21 /**
22 * A generalized Exception base class. This is nice for making general and
23 * flexible child classes that can create new error code classes.
24 *
25 * In order to create your own exception class use these two lines.
26 *
27 * in your header: subExceptionDecl( NewClassName );
28 *
29 * in your source: subExcpetienDef( NewClassName );
30 */
31 class ExceptionBase : public std::exception
32 {
33 public:
34 /**
35 * Construct an exception with an error code of zero, but with a
36 * description. The use of this is not reccomended most of the time,
37 * it's generally best to include an error code with the exception so
38 * your program can handle the exception in a better way.
39 * @param sFormat The format of the text. See printf for more info.
40 */
41 ExceptionBase( const char *sFormat, ... ) throw();
42
43 /**
44 *
45 * @param nCode
46 * @param sFormat
47 */
48 ExceptionBase( int nCode, const char *sFormat, ... ) throw();
49
50 /**
51 *
52 * @param nCode
53 * @return
54 */
55 ExceptionBase( int nCode=0 ) throw();
56
57 ExceptionBase( const ExceptionBase &e ) throw ();
58
59 /**
60 *
61 * @return
62 */
63 virtual ~ExceptionBase() throw();
64
65 /**
66 *
67 * @return
68 */
69 virtual const char *what() const throw();
70
71 /**
72 *
73 * @return
74 */
75 int getErrorCode();
76
77 /**
78 *
79 * @param lpFormat
80 * @param vargs
81 */
82 void setWhat( const char *lpFormat, va_list &vargs );
83
84 /**
85 *
86 * @param lpText
87 */
88 void setWhat( const char *lpText );
89
90 private:
91 int nErrorCode; /**< The code for the error that occured. */
92 char *sWhat; /**< The text string telling people what went wrong. */
93 };
94}
95
96#define subExceptionDecl( name ) \
97class name : public Bu::ExceptionBase \
98{ \
99 public: \
100 name( const char *sFormat, ... ) throw (); \
101 name( int nCode, const char *sFormat, ... ) throw(); \
102 name( int nCode=0 ) throw (); \
103 name( const name &e ) throw (); \
104};
105
106#define subExceptionDeclChild( name, parent ) \
107class name : public parent \
108{ \
109 public: \
110 name( const char *sFormat, ... ) throw (); \
111 name( int nCode, const char *sFormat, ... ) throw(); \
112 name( int nCode=0 ) throw (); \
113 name( const name &e ) throw (); \
114};
115
116#define subExceptionDeclBegin( name ) \
117class name : public Bu::ExceptionBase \
118{ \
119 public: \
120 name( const char *sFormat, ... ) throw (); \
121 name( int nCode, const char *sFormat, ... ) throw(); \
122 name( int nCode=0 ) throw (); \
123 name( const name &e ) throw ();
124
125#define subExceptionDeclEnd() \
126};
127
128#define subExceptionDef( name ) \
129name::name( const char *lpFormat, ... ) throw() : \
130 ExceptionBase( 0 ) \
131{ \
132 va_list ap; \
133 va_start( ap, lpFormat ); \
134 setWhat( lpFormat, ap ); \
135 va_end( ap ); \
136} \
137name::name( int nCode, const char *lpFormat, ... ) throw() : \
138 ExceptionBase( nCode ) \
139{ \
140 va_list ap; \
141 va_start( ap, lpFormat ); \
142 setWhat( lpFormat, ap ); \
143 va_end( ap ); \
144} \
145name::name( int nCode ) throw() : \
146 ExceptionBase( nCode ) \
147{ \
148} \
149name::name( const name &e ) throw() : \
150 ExceptionBase( e ) \
151{ \
152}
153
154#define subExceptionDefChild( name, parent ) \
155name::name( const char *lpFormat, ... ) throw() : \
156 parent( 0 ) \
157{ \
158 va_list ap; \
159 va_start( ap, lpFormat ); \
160 setWhat( lpFormat, ap ); \
161 va_end( ap ); \
162} \
163name::name( int nCode, const char *lpFormat, ... ) throw() : \
164 parent( nCode ) \
165{ \
166 va_list ap; \
167 va_start( ap, lpFormat ); \
168 setWhat( lpFormat, ap ); \
169 va_end( ap ); \
170} \
171name::name( int nCode ) throw() : \
172 parent( nCode ) \
173{ \
174} \
175name::name( const name &e ) throw() : \
176 ExceptionBase( e ) \
177{ \
178}
179
180namespace Bu
181{
182 // Exceptions that are so general they could be used anywhere go here.
183 class UnsupportedException : public Bu::ExceptionBase
184 {
185 public:
186 UnsupportedException() throw ();
187 };
188}
189
190#endif