Updated documentation
[libs.git] / docs / html / _exception_8h-source.html
blob770924dd6295e423c8b38c001609b5a14c325dc9
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3 <title>LibSylph: Sylph/Core/Exception.h Source File</title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.5.8 -->
7 <div class="navigation" id="top">
8 <div class="tabs">
9 <ul>
10 <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
11 <li><a href="namespaces.html"><span>Namespaces</span></a></li>
12 <li><a href="classes.html"><span>Classes</span></a></li>
13 <li class="current"><a href="files.html"><span>Files</span></a></li>
14 <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
15 </ul>
16 </div>
17 <div class="tabs">
18 <ul>
19 <li><a href="files.html"><span>File&nbsp;List</span></a></li>
20 </ul>
21 </div>
22 <h1>Sylph/Core/Exception.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
23 <a name="l00002"></a>00002 <span class="comment"> * LibSylph Class Library</span>
24 <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2009 Frank "SeySayux" Erens &lt;seysayux@gmail.com&gt;</span>
25 <a name="l00004"></a>00004 <span class="comment"> *</span>
26 <a name="l00005"></a>00005 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
27 <a name="l00006"></a>00006 <span class="comment"> * modify it under the terms of the LibSylph Pulbic License as published</span>
28 <a name="l00007"></a>00007 <span class="comment"> * by the LibSylph Developers; either version 1.0 of the License, or</span>
29 <a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
30 <a name="l00009"></a>00009 <span class="comment"> *</span>
31 <a name="l00010"></a>00010 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
32 <a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
33 <a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LibSylph</span>
34 <a name="l00013"></a>00013 <span class="comment"> * Public License for more details.</span>
35 <a name="l00014"></a>00014 <span class="comment"> *</span>
36 <a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the LibSylph Public License</span>
37 <a name="l00016"></a>00016 <span class="comment"> * along with this Library, if not, contact the LibSylph Developers.</span>
38 <a name="l00017"></a>00017 <span class="comment"> *</span>
39 <a name="l00018"></a>00018 <span class="comment"> * Created on 14 november 2008, 8:07</span>
40 <a name="l00019"></a>00019 <span class="comment"> */</span>
41 <a name="l00020"></a>00020
42 <a name="l00021"></a>00021 <span class="preprocessor">#ifndef EXCEPTION_H_</span>
43 <a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define EXCEPTION_H_</span>
44 <a name="l00023"></a>00023 <span class="preprocessor"></span>
45 <a name="l00024"></a>00024 <span class="preprocessor">#include "Object.h"</span>
46 <a name="l00025"></a>00025
47 <a name="l00026"></a>00026 <span class="preprocessor">#include &lt;exception&gt;</span>
48 <a name="l00027"></a>00027 <span class="preprocessor">#include "Primitives.h"</span>
49 <a name="l00028"></a>00028 <span class="preprocessor">#include "CurrentFunction.h"</span>
50 <a name="l00029"></a>00029
51 <a name="l00030"></a>00030 SYLPH_BEGIN_NAMESPACE
52 <a name="l00031"></a>00031
53 <a name="l00075"></a><a class="code" href="class_sylph_1_1_exception.html">00075</a> <span class="keyword">class </span><a class="code" href="class_sylph_1_1_exception.html" title="This class provides a ready-to-use interface for exception handling.">Exception</a> : <span class="keyword">public</span> std::exception {
54 <a name="l00076"></a>00076 <span class="keyword">public</span>:
55 <a name="l00090"></a><a class="code" href="class_sylph_1_1_exception.html#0f450c97db441da6ac67dae78388ada5">00090</a> <a class="code" href="class_sylph_1_1_exception.html" title="This class provides a ready-to-use interface for exception handling.">Exception</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * r = <span class="stringliteral">""</span>, <span class="keyword">const</span> <span class="keywordtype">char</span> * f = <span class="stringliteral">"unknown"</span>,
56 <a name="l00091"></a>00091 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> l = 0)
57 <a name="l00092"></a>00092 throw () : _reason(r), _file(f), _line(l), tracemsg(0) {
58 <a name="l00093"></a>00093 }
59 <a name="l00094"></a>00094
60 <a name="l00099"></a><a class="code" href="class_sylph_1_1_exception.html#0a1244e5e39e0c176247e7eca88fd6b2">00099</a> <span class="keyword">virtual</span> <a class="code" href="class_sylph_1_1_exception.html#0a1244e5e39e0c176247e7eca88fd6b2" title="Default destructor.">~Exception</a>() throw () {
61 <a name="l00100"></a>00100 TraceMessage * current = tracemsg;
62 <a name="l00101"></a>00101 <span class="keywordflow">while</span>(current != null) {
63 <a name="l00102"></a>00102 TraceMessage * tmp = current;
64 <a name="l00103"></a>00103 current = tmp-&gt;next;
65 <a name="l00104"></a>00104 <span class="keyword">delete</span> tmp;
66 <a name="l00105"></a>00105 }
67 <a name="l00106"></a>00106 }
68 <a name="l00107"></a>00107
69 <a name="l00113"></a><a class="code" href="class_sylph_1_1_exception.html#3b56cc13b4004aa72e7ea86f034f968c">00113</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="class_sylph_1_1_exception.html#3b56cc13b4004aa72e7ea86f034f968c" title="Returns the reason why this Exception was thrown, i.e. the second parameter to sthrow()...">what</a>() <span class="keyword">const</span> throw () {
70 <a name="l00114"></a>00114 <span class="keywordflow">return</span> _reason;
71 <a name="l00115"></a>00115 }
72 <a name="l00116"></a>00116
73 <a name="l00124"></a><a class="code" href="class_sylph_1_1_exception.html#16528d47441cf5ffb45bcdbd119d1661">00124</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="class_sylph_1_1_exception.html#16528d47441cf5ffb45bcdbd119d1661" title="Returns the class name of this Exception.">name</a>() <span class="keyword">const</span> throw() {
74 <a name="l00125"></a>00125 <span class="keywordflow">return</span> <span class="stringliteral">"Exception"</span>;
75 <a name="l00126"></a>00126 }
76 <a name="l00127"></a>00127
77 <a name="l00136"></a><a class="code" href="class_sylph_1_1_exception.html#1038e3fb0e96d4733beb0ea03c4aad04">00136</a> <span class="keywordtype">void</span> <a class="code" href="class_sylph_1_1_exception.html#1038e3fb0e96d4733beb0ea03c4aad04" title="This function adds a message to the trace information inside this Exception.">addTraceMessage</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * message) <span class="keyword">const</span> <span class="keywordflow">throw</span>() {
78 <a name="l00137"></a>00137 <span class="keywordflow">if</span>(tracemsg == null) {
79 <a name="l00138"></a>00138 tracemsg = <span class="keyword">new</span> TraceMessage{message,null};
80 <a name="l00139"></a>00139 } <span class="keywordflow">else</span> {
81 <a name="l00140"></a>00140 TraceMessage * current = tracemsg;
82 <a name="l00141"></a>00141 <span class="keywordflow">while</span>(current-&gt;next != null) {
83 <a name="l00142"></a>00142 current = current-&gt;next;
84 <a name="l00143"></a>00143 }
85 <a name="l00144"></a>00144 current-&gt;next = <span class="keyword">new</span> TraceMessage{message,null};
86 <a name="l00145"></a>00145 }
87 <a name="l00146"></a>00146 }
88 <a name="l00147"></a>00147
89 <a name="l00148"></a>00148 <span class="keyword">mutable</span> <span class="keyword">struct </span>TraceMessage {
90 <a name="l00149"></a>00149 <span class="keyword">mutable</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * message;
91 <a name="l00150"></a>00150 <span class="keyword">mutable</span> TraceMessage * next;
92 <a name="l00151"></a>00151 } * tracemsg;
93 <a name="l00152"></a>00152 <span class="keyword">protected</span>:
94 <a name="l00153"></a>00153 <span class="keyword">const</span> <span class="keywordtype">char</span> * _reason;
95 <a name="l00154"></a>00154 <span class="keyword">public</span>:
96 <a name="l00155"></a>00155 <span class="preprocessor">#ifndef SYLPH_DOXYGEN</span>
97 <a name="l00156"></a>00156 <span class="preprocessor"></span> <span class="keyword">const</span> <span class="keywordtype">char</span> * _file;
98 <a name="l00157"></a>00157 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> _line;
99 <a name="l00158"></a>00158 <span class="preprocessor">#endif</span>
100 <a name="l00159"></a>00159 <span class="preprocessor"></span>};
101 <a name="l00160"></a>00160
102 <a name="l00161"></a>00161 <span class="preprocessor">#define S_CREATE_EXCEPTION(Class) \</span>
103 <a name="l00162"></a>00162 <span class="preprocessor">class Class : public ::Sylph::Exception { \</span>
104 <a name="l00163"></a>00163 <span class="preprocessor">public: \</span>
105 <a name="l00164"></a>00164 <span class="preprocessor"> Class(const char * r = "", const char * f = "unknown", \</span>
106 <a name="l00165"></a>00165 <span class="preprocessor"> const unsigned int l = 0) \</span>
107 <a name="l00166"></a>00166 <span class="preprocessor"> throw () : ::Sylph::Exception(r,f,l) { \</span>
108 <a name="l00167"></a>00167 <span class="preprocessor"> } \</span>
109 <a name="l00168"></a>00168 <span class="preprocessor"> virtual const char* name() const throw() {\</span>
110 <a name="l00169"></a>00169 <span class="preprocessor"> return #Class ; \</span>
111 <a name="l00170"></a>00170 <span class="preprocessor"> }\</span>
112 <a name="l00171"></a>00171 <span class="preprocessor">}</span>
113 <a name="l00172"></a>00172 <span class="preprocessor"></span>
114 <a name="l00173"></a>00173 <span class="preprocessor">#define S_CREATE_EXCEPTION2(Class,Base) \</span>
115 <a name="l00174"></a>00174 <span class="preprocessor">class Class : public Base { \</span>
116 <a name="l00175"></a>00175 <span class="preprocessor">public: \</span>
117 <a name="l00176"></a>00176 <span class="preprocessor"> Class(const char * r = "", const char * f = "unknown", \</span>
118 <a name="l00177"></a>00177 <span class="preprocessor"> const unsigned int l = 0) \</span>
119 <a name="l00178"></a>00178 <span class="preprocessor"> throw () : Base(r,f,l) { \</span>
120 <a name="l00179"></a>00179 <span class="preprocessor"> } \</span>
121 <a name="l00180"></a>00180 <span class="preprocessor"> virtual const char* name() const throw() {\</span>
122 <a name="l00181"></a>00181 <span class="preprocessor"> return #Class ; \</span>
123 <a name="l00182"></a>00182 <span class="preprocessor"> }\</span>
124 <a name="l00183"></a>00183 <span class="preprocessor">}</span>
125 <a name="l00184"></a>00184 <span class="preprocessor"></span>
126 <a name="l00190"></a><a class="code" href="class_sylph_1_1_array_exception.html#a08a8b44fe9a17a7d49fbf7901337da1">00190</a> S_CREATE_EXCEPTION(<a class="code" href="class_sylph_1_1_array_exception.html" title="A generic Exception when an error occurs with an Array.">ArrayException</a>);
127 <a name="l00191"></a>00191 S_CREATE_EXCEPTION(EncodingException);
128 <a name="l00196"></a><a class="code" href="class_sylph_1_1_file_exception.html#ed1e2488c6e6546ae805eeef2c0c166b">00196</a> S_CREATE_EXCEPTION(<a class="code" href="class_sylph_1_1_file_exception.html" title="A genreric Exception which gets thrown whenever something goes wrong in the File...">FileException</a>);
129 <a name="l00202"></a><a class="code" href="class_sylph_1_1_i_o_exception.html#3fbf12448999e9e0b68a1c3bbd36a742">00202</a> S_CREATE_EXCEPTION(<a class="code" href="class_sylph_1_1_i_o_exception.html" title="This is a generic exception for I/O errors.">IOException</a>);
130 <a name="l00207"></a><a class="code" href="class_sylph_1_1_illegal_argument_exception.html#32f8fb7f6fc25f97a82053face9304e8">00207</a> S_CREATE_EXCEPTION(<a class="code" href="class_sylph_1_1_illegal_argument_exception.html" title="Generic exception to flag an argument with an illegal state was passed to an function...">IllegalArgumentException</a>);
131 <a name="l00212"></a><a class="code" href="class_sylph_1_1_illegal_state_exception.html#8e46190d7b17a2f8b62c4dd51ef83508">00212</a> S_CREATE_EXCEPTION(<a class="code" href="class_sylph_1_1_illegal_state_exception.html" title="Generic exception to flag that a method is not supported in the current state of...">IllegalStateException</a>);
132 <a name="l00218"></a><a class="code" href="class_sylph_1_1_null_pointer_exception.html#a2dce7a7d789fe26a2de523bdf0358f2">00218</a> S_CREATE_EXCEPTION(<a class="code" href="class_sylph_1_1_null_pointer_exception.html" title="This Exception gets thrown when a pointer to null is passed to a function or method...">NullPointerException</a>);
133 <a name="l00223"></a><a class="code" href="class_sylph_1_1_serialization_exception.html#644a24bfe9e0d21c368155324d9ae33f">00223</a> S_CREATE_EXCEPTION(<a class="code" href="class_sylph_1_1_serialization_exception.html" title="This Exception gets thrown if there is a problem with serializing or deserializing...">SerializationException</a>);
134 <a name="l00224"></a>00224
135 <a name="l00225"></a>00225 SYLPH_END_NAMESPACE
136 <a name="l00226"></a>00226
137 <a name="l00227"></a>00227
138 <a name="l00228"></a>00228 <span class="preprocessor">#ifdef SYLPH_DEBUG</span>
139 <a name="l00229"></a>00229 <span class="preprocessor"></span><span class="preprocessor">#define sthrow(__x, __r) throw __x(__r, __FILE__, __LINE__)</span>
140 <a name="l00230"></a>00230 <span class="preprocessor"></span><span class="preprocessor">#else</span>
141 <a name="l00231"></a>00231 <span class="preprocessor"></span><span class="preprocessor">#define sthrow(__x, __r) throw __x(__r)</span>
142 <a name="l00232"></a>00232 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
143 <a name="l00233"></a>00233 <span class="preprocessor"></span>
144 <a name="l00234"></a>00234 <span class="preprocessor">#define strace \</span>
145 <a name="l00235"></a>00235 <span class="preprocessor">catch(::Sylph::Exception&amp; ex) { \</span>
146 <a name="l00236"></a>00236 <span class="preprocessor"> ex.addTraceMessage(S_CURRENT_FUNCTION); \</span>
147 <a name="l00237"></a>00237 <span class="preprocessor"> throw; \</span>
148 <a name="l00238"></a>00238 <span class="preprocessor">} do{} while(0)</span>
149 <a name="l00239"></a>00239 <span class="preprocessor"></span><span class="preprocessor">#ifdef SYLPH_DEBUG</span>
150 <a name="l00240"></a>00240 <span class="preprocessor"></span><span class="preprocessor">#define straced strace</span>
151 <a name="l00241"></a>00241 <span class="preprocessor"></span><span class="preprocessor">#else</span>
152 <a name="l00242"></a>00242 <span class="preprocessor"></span><span class="preprocessor">#define straced do{} while(0)</span>
153 <a name="l00243"></a>00243 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
154 <a name="l00244"></a>00244 <span class="preprocessor"></span>
155 <a name="l00245"></a>00245 <span class="preprocessor">#define if_nullptr(__x) if(SYLPH_UNLIKELY(__x == 0))</span>
156 <a name="l00246"></a>00246 <span class="preprocessor"></span><span class="preprocessor">#define check_nullptr(__x) if_nullptr(__x) sthrow (NullPointerException, "Dereferenced a null pointer")</span>
157 <a name="l00247"></a>00247 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* EXCEPTION_H_ */</span>
158 <a name="l00248"></a>00248
159 </pre></div></div>
160 <hr size="1" class="unhidden"><address style="text-align: right;"><small>
161 Documentation for LibSylph by Doxygen
162 </body>
163 </html>