summaryrefslogtreecommitdiffstats
path: root/labb6/lib/StanfordCPPLib/error.cpp
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-01 15:25:23 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-01 15:25:23 +0100
commit93c6b29368d1e0487937b433bc6e678da0058055 (patch)
tree5e749adfecf2eab82b5e78bbeacc52fc8e2298fb /labb6/lib/StanfordCPPLib/error.cpp
parentd4f35cf45ebc655d92cde8abb5c9a1c2822a08ba (diff)
downloadtddd86-93c6b29368d1e0487937b433bc6e678da0058055.tar.gz
given code l6
Diffstat (limited to 'labb6/lib/StanfordCPPLib/error.cpp')
-rwxr-xr-xlabb6/lib/StanfordCPPLib/error.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/labb6/lib/StanfordCPPLib/error.cpp b/labb6/lib/StanfordCPPLib/error.cpp
new file mode 100755
index 0000000..c0e0a36
--- /dev/null
+++ b/labb6/lib/StanfordCPPLib/error.cpp
@@ -0,0 +1,42 @@
+/*
+ * File: error.cpp
+ * ---------------
+ * Implementation of the error function.
+ */
+
+#include <exception>
+#include <string>
+#include <iostream>
+#include "error.h"
+using namespace std;
+
+/* Definitions for the ErrorException class */
+
+ErrorException::ErrorException(string msg) {
+ this->msg = msg;
+}
+
+ErrorException::~ErrorException() throw () {
+ /* Empty */
+}
+
+string ErrorException::getMessage() const {
+ return msg;
+}
+
+const char *ErrorException::what() const throw () {
+ return ("Error: " + msg).c_str();
+}
+
+/*
+ * Implementation notes: error
+ * ---------------------------
+ * Earlier implementations of error made it possible, at least on the
+ * Macintosh, to help the debugger generate a backtrace at the point
+ * of the error. Unfortunately, doing so is no longer possible if
+ * the errors are catchable.
+ */
+
+void error(string msg) {
+ throw ErrorException(msg);
+}