aboutsummaryrefslogtreecommitdiff
path: root/src/exception.cpp
blob: 11f04a924005a7c562ee6b485db12db0bf326bc4 (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
#include "exception.h"
#include <stdarg.h>

Exception::Exception( const char *lpFormat, ... ) throw() :
	nErrorCode( 0 )
{
	va_list ap;
	int nSize;

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

Exception::Exception( int nCode, const char *lpFormat, ... ) throw() :
	nErrorCode( nCode )
{
	va_list ap;
	int nSize;

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

Exception::~Exception() throw()
{
	delete[] sWhat;
}

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

int Exception::getErrorCode()
{
	return nErrorCode;
}