summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/error.cpp
blob: c0e0a366a08ce6eab3813c3105f1c139181ca5bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
}