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