diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-12-03 17:11:43 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-12-08 10:21:07 +0100 |
| commit | 0c39051ba80f04b1177833a006f2d442a7170b56 (patch) | |
| tree | 9e657946a061b5b305f9cf75634db7b37e979eb3 /labb8/lib/StanfordCPPLib/error.h | |
| parent | 7b7f6808a7b2db2ed21103767434c1445f7815c2 (diff) | |
| download | tddd86-0c39051ba80f04b1177833a006f2d442a7170b56.tar.gz | |
add initial files l8
Diffstat (limited to 'labb8/lib/StanfordCPPLib/error.h')
| -rwxr-xr-x | labb8/lib/StanfordCPPLib/error.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/labb8/lib/StanfordCPPLib/error.h b/labb8/lib/StanfordCPPLib/error.h new file mode 100755 index 0000000..359ea99 --- /dev/null +++ b/labb8/lib/StanfordCPPLib/error.h @@ -0,0 +1,56 @@ +/* + * File: error.h + * ------------- + * This file defines the <code>ErrorException</code> class and the + * <code>error</code> function. + */ + +#ifndef _error_h +#define _error_h + +#include <string> +#include <exception> + +/* + * Class: ErrorException + * --------------------- + * This exception is thrown by calls to the <code>error</code> + * function. Typical code for catching errors looks like this: + * + *<pre> + * try { + * ... code in which an error might occur ... + * } catch (ErrorException & ex) { + * ... code to handle the error condition ... + * } + *</pre> + * + * If an <code>ErrorException</code> is thrown at any point in the + * range of the <code>try</code> (including in functions called from + * that code), control will jump immediately to the error handler. + */ + +class ErrorException : public std::exception { +public: + ErrorException(std::string msg); + virtual ~ErrorException() throw (); + virtual std::string getMessage() const; + virtual const char *what() const throw (); + +private: + std::string msg; +}; + +/* + * Function: error + * Usage: error(msg); + * ------------------ + * Signals an error condition in a program by throwing an + * <code>ErrorException</code> with the specified message. + */ + +void error(std::string msg); + +#include "private/main.h" + +#endif |
