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.h | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 labb8/lib/StanfordCPPLib/error.h (limited to 'labb8/lib/StanfordCPPLib/error.h') 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 ErrorException class and the + * error function. + */ + +#ifndef _error_h +#define _error_h + +#include +#include + +/* + * Class: ErrorException + * --------------------- + * This exception is thrown by calls to the error + * function. Typical code for catching errors looks like this: + * + *
+ *    try {
+ *       ... code in which an error might occur ...
+ *    } catch (ErrorException & ex) {
+ *       ... code to handle the error condition ...
+ *    }
+ *
+ * + * If an ErrorException is thrown at any point in the + * range of the try (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 + * ErrorException with the specified message. + */ + +void error(std::string msg); + +#include "private/main.h" + +#endif -- cgit v1.2.1