aboutsummaryrefslogtreecommitdiff
path: root/src/exceptionbase.cpp
blob: 73a7b0ec2619cb36bde00e0e2fb5351564890363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "exceptionbase.h"
#include <stdarg.h>

Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() :
	nErrorCode( 0 ),
	sWhat( NULL )
{
	va_list ap;

	va_start(ap, lpFormat);
	setWhat( lpFormat, ap );
	va_end(ap);
}

Bu::ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() :
	nErrorCode( nCode ),
	sWhat( NULL )
{
	va_list ap;

	va_start(ap, lpFormat);
	setWhat( lpFormat, ap );
	va_end(ap);
}

Bu::ExceptionBase::ExceptionBase( int nCode ) throw() :
	nErrorCode( nCode ),
	sWhat( NULL )
{
}

Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () :
	nErrorCode( e.nErrorCode ),
	sWhat( NULL )
{
	setWhat( e.sWhat );
}

Bu::ExceptionBase::~ExceptionBase() throw()
{
	if( sWhat )
	{
		delete[] sWhat;
		sWhat = NULL;
	}
}

void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs )
{
	if( sWhat ) delete[] sWhat;
	int nSize;

	nSize = vsnprintf( NULL, 0, lpFormat, vargs );
	sWhat = new char[nSize+1];
	vsnprintf( sWhat, nSize+1, lpFormat, vargs );
}

void Bu::ExceptionBase::setWhat( const char *lpText )
{
	if( sWhat ) delete[] sWhat;
	int nSize;

	nSize = strlen( lpText );
	sWhat = new char[nSize+1];
	strcpy( sWhat, lpText );
}

const char *Bu::ExceptionBase::what() const throw()
{
	return sWhat;
}

int Bu::ExceptionBase::getErrorCode()
{
	return nErrorCode;
}