summaryrefslogtreecommitdiff
path: root/project2/exceptions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/exceptions.cpp')
-rw-r--r--project2/exceptions.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/project2/exceptions.cpp b/project2/exceptions.cpp
index 9aaeb07..ddf8e94 100644
--- a/project2/exceptions.cpp
+++ b/project2/exceptions.cpp
@@ -1,7 +1,26 @@
#include "exceptions.h"
+#include <stdlib.h>
+#include <stdio.h>
-NotSupported::NotSupported(const std::string & what) :
- std::runtime_error(what)
+numeric_error::numeric_error(int e) :
+ err(e),
+ buf(NULL)
{
}
+numeric_error::~numeric_error() throw()
+{
+ free(buf);
+}
+
+const char *
+numeric_error::what() const throw()
+{
+ if (!buf) {
+ if (asprintf(&buf, "%d", err) < 1) {
+ throw std::bad_alloc();
+ }
+ }
+ return buf;
+}
+