summaryrefslogtreecommitdiff
path: root/src/exception.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-05-13 02:24:07 +0000
committerMike Buland <eichlan@xagasoft.com>2006-05-13 02:24:07 +0000
commitbc6f456ef27bdf25bf7a7f677217b9b7204b4241 (patch)
tree6b4f93f7448dde93240a0ba8d3643a37462f66ff /src/exception.cpp
parente6fc69187632612974cc650c28fe17d5a6d38e6a (diff)
downloadlibbu++-bc6f456ef27bdf25bf7a7f677217b9b7204b4241.tar.gz
libbu++-bc6f456ef27bdf25bf7a7f677217b9b7204b4241.tar.bz2
libbu++-bc6f456ef27bdf25bf7a7f677217b9b7204b4241.tar.xz
libbu++-bc6f456ef27bdf25bf7a7f677217b9b7204b4241.zip
Added a nice, generic exception class. It really helps out a lot. I dunno if
it's better to create a new subclass of it for each situation, but it is cool...
Diffstat (limited to 'src/exception.cpp')
-rw-r--r--src/exception.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/exception.cpp b/src/exception.cpp
new file mode 100644
index 0000000..11f04a9
--- /dev/null
+++ b/src/exception.cpp
@@ -0,0 +1,44 @@
1#include "exception.h"
2#include <stdarg.h>
3
4Exception::Exception( const char *lpFormat, ... ) throw() :
5 nErrorCode( 0 )
6{
7 va_list ap;
8 int nSize;
9
10 va_start(ap, lpFormat);
11 nSize = vsnprintf( NULL, 0, lpFormat, ap );
12 sWhat = new char[nSize+1];
13 vsnprintf( sWhat, nSize+1, lpFormat, ap );
14 va_end(ap);
15}
16
17Exception::Exception( int nCode, const char *lpFormat, ... ) throw() :
18 nErrorCode( nCode )
19{
20 va_list ap;
21 int nSize;
22
23 va_start(ap, lpFormat);
24 nSize = vsnprintf( NULL, 0, lpFormat, ap );
25 sWhat = new char[nSize+1];
26 vsnprintf( sWhat, nSize+1, lpFormat, ap );
27 va_end(ap);
28}
29
30Exception::~Exception() throw()
31{
32 delete[] sWhat;
33}
34
35const char *Exception::what() const throw()
36{
37 return sWhat;
38}
39
40int Exception::getErrorCode()
41{
42 return nErrorCode;
43}
44