From 0c39051ba80f04b1177833a006f2d442a7170b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 3 Dec 2020 17:11:43 +0100 Subject: add initial files l8 --- labb8/lib/StanfordCPPLib/error.cpp | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 labb8/lib/StanfordCPPLib/error.cpp (limited to 'labb8/lib/StanfordCPPLib/error.cpp') diff --git a/labb8/lib/StanfordCPPLib/error.cpp b/labb8/lib/StanfordCPPLib/error.cpp new file mode 100755 index 0000000..c0e0a36 --- /dev/null +++ b/labb8/lib/StanfordCPPLib/error.cpp @@ -0,0 +1,42 @@ +/* + * File: error.cpp + * --------------- + * Implementation of the error function. + */ + +#include +#include +#include +#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); +} -- cgit v1.2.1