aboutsummaryrefslogtreecommitdiff
path: root/src/stable/exceptionbase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/exceptionbase.cpp')
-rw-r--r--src/stable/exceptionbase.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/stable/exceptionbase.cpp b/src/stable/exceptionbase.cpp
new file mode 100644
index 0000000..13a98db
--- /dev/null
+++ b/src/stable/exceptionbase.cpp
@@ -0,0 +1,93 @@
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#include "bu/exceptionbase.h"
9#include <stdarg.h>
10#include <string.h>
11#include <stdio.h>
12
13Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() :
14 nErrorCode( 0 ),
15 sWhat( NULL )
16{
17 va_list ap;
18
19 va_start(ap, lpFormat);
20 setWhat( lpFormat, ap );
21 va_end(ap);
22}
23
24Bu::ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() :
25 nErrorCode( nCode ),
26 sWhat( NULL )
27{
28 va_list ap;
29
30 va_start(ap, lpFormat);
31 setWhat( lpFormat, ap );
32 va_end(ap);
33}
34
35Bu::ExceptionBase::ExceptionBase( int nCode ) throw() :
36 nErrorCode( nCode ),
37 sWhat( NULL )
38{
39}
40
41Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () :
42 std::exception( e ),
43 nErrorCode( e.nErrorCode ),
44 sWhat( NULL )
45{
46 setWhat( e.sWhat );
47}
48
49Bu::ExceptionBase::~ExceptionBase() throw()
50{
51 delete[] sWhat;
52 sWhat = NULL;
53}
54
55void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs )
56{
57 if( sWhat ) delete[] sWhat;
58 int nSize;
59
60 va_list vargs2;
61 va_copy( vargs2, vargs );
62 nSize = vsnprintf( NULL, 0, lpFormat, vargs2 );
63 va_end( vargs2 );
64 sWhat = new char[nSize+1];
65 vsnprintf( sWhat, nSize+1, lpFormat, vargs );
66}
67
68void Bu::ExceptionBase::setWhat( const char *lpText )
69{
70 if( sWhat ) delete[] sWhat;
71 int nSize;
72
73 nSize = strlen( lpText );
74 sWhat = new char[nSize+1];
75 strcpy( sWhat, lpText );
76}
77
78const char *Bu::ExceptionBase::what() const throw()
79{
80 return sWhat;
81}
82
83int Bu::ExceptionBase::getErrorCode()
84{
85 return nErrorCode;
86}
87
88Bu::UnsupportedException::UnsupportedException() throw() :
89 ExceptionBase( 0 )
90{
91 setWhat("An unsupperted operation was attempted.");
92}
93