diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-17 15:42:27 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-17 15:42:27 +0100 |
| commit | fb80ac50825c7ca1fa063d3493175b7b27adbdb1 (patch) | |
| tree | 4d84895d45ca2c177ddefe11164575bf6762b3ca /labb5/lib/StanfordCPPLib/error.cpp | |
| parent | 4065799f7080260f507a5e3ea8c2d8375e735166 (diff) | |
| download | tddd86-fb80ac50825c7ca1fa063d3493175b7b27adbdb1.tar.gz | |
add given code
Diffstat (limited to 'labb5/lib/StanfordCPPLib/error.cpp')
| -rwxr-xr-x | labb5/lib/StanfordCPPLib/error.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/labb5/lib/StanfordCPPLib/error.cpp b/labb5/lib/StanfordCPPLib/error.cpp new file mode 100755 index 0000000..c0e0a36 --- /dev/null +++ b/labb5/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); +} |
