aboutsummaryrefslogtreecommitdiff
path: root/Exception.cpp
blob: 52e30dc816c6288d20d0fb96d7fdff13c218cbc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Exception.h"

#include <cstdarg>
#include <cstdio>

Exception::Exception(const char * fmt, ...) {
	va_list args;
	va_start(args, fmt);
	size_t sz = vsnprintf(NULL, 0, fmt, args) + 1;
	if (error != NULL) free(error);
	error = (char *) malloc(sz);
	vsnprintf(error, sz, fmt, args);
	va_end(args);
}

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

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