aboutsummaryrefslogtreecommitdiff
path: root/Exception.cpp
blob: d9765dafd69672908c44cfb82ac011560a438b31 (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
#include <cstdarg>
#include <cstdio>
#include <cstdlib>

#include "Exception.h"

Exception::~Exception() {
	if (error != NULL)
		free(error);
}

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

void Exception::va_format(va_list args, const char * fmt) {
	va_list args_copy;
	va_copy(args_copy, args);

	size_t sz = vsnprintf(NULL, 0, fmt, args_copy) + 1;
	if (error != NULL) free(error);
	error = (char *) malloc(sz);
	va_end(args_copy);

	vsnprintf(error, sz, fmt, args);
}

Exception::Exception(const char * fmt, ...) {
	va_list args;
	va_start(args, fmt);
	va_format(args, fmt);
	va_end(args);
}