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

#include "Exception.h"

using namespace std;

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

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;
	va_end(args_copy);

	this->error = unique_ptr<char>(static_cast<char *>(malloc(sz)));

	vsnprintf(this->error.get(), sz, fmt, args);
}

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