summaryrefslogtreecommitdiffabout
path: root/include
authorMichael Krelin <hacker@klever.net>2006-12-12 12:59:26 (UTC)
committer Michael Krelin <hacker@klever.net>2006-12-12 12:59:26 (UTC)
commit4c22006b8012bafccf955c0d077971e67107ac35 (patch) (unidiff)
tree0a2c5748204a701576b8951e7658066e8e1c9c2b /include
parent08868f34ee339540ca392bb19e9c537d6e769464 (diff)
downloadkonforka-4c22006b8012bafccf955c0d077971e67107ac35.zip
konforka-4c22006b8012bafccf955c0d077971e67107ac35.tar.gz
konforka-4c22006b8012bafccf955c0d077971e67107ac35.tar.bz2
a few exception-handling convenience definitions
Diffstat (limited to 'include') (more/less context) (ignore whitespace changes)
-rw-r--r--include/konforka/exception.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/konforka/exception.h b/include/konforka/exception.h
index 5e0bf96..dbfe27c 100644
--- a/include/konforka/exception.h
+++ b/include/konforka/exception.h
@@ -1,203 +1,234 @@
1#ifndef __KONFORKA_EXCEPTION_H 1#ifndef __KONFORKA_EXCEPTION_H
2#define __KONFORKA_EXCEPTION_H 2#define __KONFORKA_EXCEPTION_H
3 3
4#include <exception> 4#include <exception>
5#include <string> 5#include <string>
6#include <list> 6#include <list>
7 7
8/** 8/**
9 * @file 9 * @file
10 * @brief exception-related stuff. 10 * @brief exception-related stuff.
11 * 11 *
12 * Basic exception-related declarations and definitions. 12 * Basic exception-related declarations and definitions.
13 */ 13 */
14 14
15/** 15/**
16 * @def CODEPOINT 16 * @def CODEPOINT
17 * the convenience definition of the parameters passed to the 17 * the convenience definition of the parameters passed to the
18 * konforka::code_point constructor. 18 * konforka::code_point constructor.
19 */ 19 */
20 #defineCODEPOINT __FILE__,__PRETTY_FUNCTION__,__LINE__ 20 #defineCODEPOINT __FILE__,__PRETTY_FUNCTION__,__LINE__
21/** 21/**
22 * @def NOCODEPOINT 22 * @def NOCODEPOINT
23 * the convenience definition for the codepoint denoting no particular point in 23 * the convenience definition for the codepoint denoting no particular point in
24 * code. 24 * code.
25 */ 25 */
26#define NOCODEPOINT "no information" 26#define NOCODEPOINT "no information"
27 27
28/** 28/**
29 * @def KONFORKA_RETHROW
30 * the convenience definition for seeing the exception and rethrowing it further.
31 */
32#define KONFORKA_RETHROW catch(konforka::exception& e) { e.see(CODEPOINT); throw; }
33
34/**
35 * @def KONFORKA_E_ARGS
36 * the convenience definition for naming codepoint parameters
37 */
38#define KONFORKA_E_PARS const string& fi,const string& fu,int l,const string& w
39
40/**
41 * @def KONFORKA_E_CONS
42 * the convenience definition for passing parameters to constructor
43 */
44#define KONFORKA_E_CONS fi,fu,l,w
45
46/**
47 * @def KONFORKA_E_SUBCLASS
48 * the convenience definition for subclassing konforka exceptions
49 * @param base base class
50 * @param derived derived class
51 */
52#define KONFORKA_E_SUBCLASS(derived,base) \
53 class derived : public base { \
54 public: \
55 explicit derived(KONFORKA_E_PARS) \
56 : base(KONFORKA_E_CONS) { } \
57 }
58
59/**
29 * @brief The main konforka namespace. 60 * @brief The main konforka namespace.
30 */ 61 */
31namespace konforka { 62namespace konforka {
32 using std::string; 63 using std::string;
33 using std::list; 64 using std::list;
34 65
35 /** 66 /**
36 * @brief Pinpoint the code context. 67 * @brief Pinpoint the code context.
37 * 68 *
38 * Class, holding the point in code, for instance, where the exception 69 * Class, holding the point in code, for instance, where the exception
39 * occured. 70 * occured.
40 */ 71 */
41 class code_point { 72 class code_point {
42 public: 73 public:
43 /** 74 /**
44 * The string describing the point in code. 75 * The string describing the point in code.
45 */ 76 */
46 string where; 77 string where;
47 /** 78 /**
48 * The file (as provided by __FILE__) if available. 79 * The file (as provided by __FILE__) if available.
49 */ 80 */
50 string file; 81 string file;
51 /** 82 /**
52 * The function name (as provided by __PRETTY_FUNCTION__) if 83 * The function name (as provided by __PRETTY_FUNCTION__) if
53 * available. 84 * available.
54 */ 85 */
55 string function; 86 string function;
56 /** 87 /**
57 * The line number (as provided by __LINE__) if available. 88 * The line number (as provided by __LINE__) if available.
58 */ 89 */
59 int line; 90 int line;
60 91
61 /** 92 /**
62 * Constructs the object, using only textual description of the 93 * Constructs the object, using only textual description of the
63 * point in code (no file, function, line information). 94 * point in code (no file, function, line information).
64 * @param w the description of the point in code. 95 * @param w the description of the point in code.
65 */ 96 */
66 code_point(const string& w); 97 code_point(const string& w);
67 /** 98 /**
68 * Constructs the object, specifying the exact position in code. 99 * Constructs the object, specifying the exact position in code.
69 * @param fi source file name. 100 * @param fi source file name.
70 * @param fu function name. 101 * @param fu function name.
71 * @param l the line number. 102 * @param l the line number.
72 */ 103 */
73 code_point(const string& fi,const string& fu,int l); 104 code_point(const string& fi,const string& fu,int l);
74 105
75 /** 106 /**
76 * Extract the information on the point in code. 107 * Extract the information on the point in code.
77 * @return the reference to the character string. 108 * @return the reference to the character string.
78 * @see where 109 * @see where
79 */ 110 */
80 const char *c_str() const throw(); 111 const char *c_str() const throw();
81 112
82 /** 113 /**
83 * Build the textual description from the broken down information on 114 * Build the textual description from the broken down information on
84 * the point in code. 115 * the point in code.
85 * @see where 116 * @see where
86 * @see file 117 * @see file
87 * @see function 118 * @see function
88 * @see line 119 * @see line
89 */ 120 */
90 void make_where(); 121 void make_where();
91 }; 122 };
92 123
93 /** 124 /**
94 * @brief The basic exception class. 125 * @brief The basic exception class.
95 */ 126 */
96 class exception : public std::exception { 127 class exception : public std::exception {
97 public: 128 public:
98 /** 129 /**
99 * The string, containing the description of exception. 130 * The string, containing the description of exception.
100 */ 131 */
101 string _what; 132 string _what;
102 /** 133 /**
103 * Reference to the point in code where the exception has occured. 134 * Reference to the point in code where the exception has occured.
104 */ 135 */
105 code_point _where; 136 code_point _where;
106 /** 137 /**
107 * In case the exception has been rethrown a number of times, here 138 * In case the exception has been rethrown a number of times, here
108 * we can trace where was it seen (a kind of backtrace). 139 * we can trace where was it seen (a kind of backtrace).
109 */ 140 */
110 list<code_point> _seen; 141 list<code_point> _seen;
111 142
112 /** 143 /**
113 * The simple constructor, only providing textual information on the 144 * The simple constructor, only providing textual information on the
114 * exception nature and the point in code where the exception has 145 * exception nature and the point in code where the exception has
115 * occured. 146 * occured.
116 * @param whe the point in code. 147 * @param whe the point in code.
117 * @param wha the description of exception. 148 * @param wha the description of exception.
118 */ 149 */
119 exception(const string& whe, const string& wha); 150 exception(const string& whe, const string& wha);
120 /** 151 /**
121 * The constructor, storing elaborate information on where the 152 * The constructor, storing elaborate information on where the
122 * exception has occured. 153 * exception has occured.
123 * @param fi source file name. 154 * @param fi source file name.
124 * @param fu function name. 155 * @param fu function name.
125 * @param l line number. 156 * @param l line number.
126 * @param w the error message. 157 * @param w the error message.
127 * @see #CODEPOINT 158 * @see #CODEPOINT
128 */ 159 */
129 exception(const string& fi,const string& fu,int l,const string& w); 160 exception(const string& fi,const string& fu,int l,const string& w);
130 virtual ~exception() throw(); 161 virtual ~exception() throw();
131 162
132 /** 163 /**
133 * Extract the textual information on the point in code where 164 * Extract the textual information on the point in code where
134 * exception has occured. 165 * exception has occured.
135 * @return the string describing point in code where exception has 166 * @return the string describing point in code where exception has
136 * occured. 167 * occured.
137 */ 168 */
138 virtual const char* where() const throw(); 169 virtual const char* where() const throw();
139 /** 170 /**
140 * Extract the textual information on the nature of the exception. 171 * Extract the textual information on the nature of the exception.
141 * @return the error message. 172 * @return the error message.
142 */ 173 */
143 virtual const char* what() const throw(); 174 virtual const char* what() const throw();
144 175
145 /** 176 /**
146 * Register the point in code (described by the string) in the 177 * Register the point in code (described by the string) in the
147 * 'backtrace' list. 178 * 'backtrace' list.
148 * @param w the description of the point in code. 179 * @param w the description of the point in code.
149 */ 180 */
150 void see(const string& w); 181 void see(const string& w);
151 /** 182 /**
152 * Register the point in code in the 'backtrace' list. 183 * Register the point in code in the 'backtrace' list.
153 * @param fi souce file name. 184 * @param fi souce file name.
154 * @param fu function name. 185 * @param fu function name.
155 * @param l line number. 186 * @param l line number.
156 * @see CODEPOINT 187 * @see CODEPOINT
157 */ 188 */
158 void see(const string& fi,const string& fu,int l); 189 void see(const string& fi,const string& fu,int l);
159 }; 190 };
160 191
161 /** 192 /**
162 * @brief errno-holding exception. 193 * @brief errno-holding exception.
163 * 194 *
164 * The exception object storing the information provided by the errno 195 * The exception object storing the information provided by the errno
165 * variable. 196 * variable.
166 */ 197 */
167 class system_error : public exception { 198 class system_error : public exception {
168 public: 199 public:
169 /** 200 /**
170 * The value of errno. 201 * The value of errno.
171 */ 202 */
172 int _errno; 203 int _errno;
173 204
174 /** 205 /**
175 * Construct the exception object storing plain text information on 206 * Construct the exception object storing plain text information on
176 * the point in code. 207 * the point in code.
177 * @param whe the description of point in code. 208 * @param whe the description of point in code.
178 * @param wha the error message. 209 * @param wha the error message.
179 */ 210 */
180 system_error(const string& whe,const string& wha); 211 system_error(const string& whe,const string& wha);
181 /** 212 /**
182 * Construct the exception object storing elaborate information on 213 * Construct the exception object storing elaborate information on
183 * the point in code where it has occured. 214 * the point in code where it has occured.
184 * @param fi source file name. 215 * @param fi source file name.
185 * @param fu function name. 216 * @param fu function name.
186 * @param l line number. 217 * @param l line number.
187 * @param w the error message. 218 * @param w the error message.
188 * @see CODEPOINT 219 * @see CODEPOINT
189 */ 220 */
190 system_error(const string& fi,const string& fu,int l,const string& w); 221 system_error(const string& fi,const string& fu,int l,const string& w);
191 virtual ~system_error() throw(); 222 virtual ~system_error() throw();
192 223
193 /** 224 /**
194 * Return the information on the system error recorded. 225 * Return the information on the system error recorded.
195 * @return the string describing the error occured. 226 * @return the string describing the error occured.
196 */ 227 */
197 virtual const char* why() const throw(); 228 virtual const char* why() const throw();
198 }; 229 };
199 230
200} 231}
201 232
202#endif /* __KONFORKA_EXCEPTION_H */ 233#endif /* __KONFORKA_EXCEPTION_H */
203/* vim:set ft=cpp: */ 234/* vim:set ft=cpp: */