diff options
Diffstat (limited to 'Exception.cpp')
-rw-r--r-- | Exception.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Exception.cpp b/Exception.cpp new file mode 100644 index 0000000..52e30dc --- /dev/null +++ b/Exception.cpp @@ -0,0 +1,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; +}
\ No newline at end of file |