Frobby  0.9.5
error.h
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see http://www.gnu.org/licenses/.
16 */
17 #ifndef ERROR_GUARD
18 #define ERROR_GUARD
19 
20 #include <stdexcept>
21 #include <string>
22 
23 class Scanner;
24 
27 class FrobbyException : public std::runtime_error {
28  public:
29  FrobbyException(const string& str): runtime_error(str) {}
30 };
31 
33 class InternalFrobbyException : public std::logic_error {
34  public:
35  InternalFrobbyException(const string& str): logic_error(str) {}
36 };
37 
38 // The do {...} while (0) is to collect everything into a single
39 // statement that still requires a semicolon after it. The throw is to
40 // prevent spurious compiler warnings about a missing return
41 // statement.
42 #define INTERNAL_ERROR(msg) \
43  do { \
44  reportInternalError(msg, __FILE__, __LINE__); \
45  throw; \
46  } while (false)
47 #define INTERNAL_ERROR_UNIMPLEMENTED() \
48  INTERNAL_ERROR("Called function that has not been implemented.")
49 
50 // These methods throw exceptions.
51 void reportError(const string& errorMsg);
52 void reportInternalError(const string& errorMsg);
54 (const string& errorMsg, const char* file, unsigned int lineNumber);
55 void reportSyntaxError(const Scanner& scanner, const string& errorMsg);
56 
57 template<class Exception>
58 void throwError(const string& errorMsg) {
59  throw Exception("ERROR: " + errorMsg + '\n');
60 }
61 
62 
63 #define DEFINE_EXCEPTION(NAME) \
64  class NAME##Exception : public FrobbyException { \
65  public: \
66  NAME##Exception(const string& str): FrobbyException(str) {} \
67  }
68 
69 DEFINE_EXCEPTION(UnknownName);
70 DEFINE_EXCEPTION(AmbiguousName);
71 DEFINE_EXCEPTION(Unsupported);
72 
73 #endif
This is the base of the Frobby exception hierarchy for exceptions that can occur due to expected erro...
Definition: error.h:27
FrobbyException(const string &str)
Definition: error.h:29
This exception signals that a bug in Frobby has been detected.
Definition: error.h:33
InternalFrobbyException(const string &str)
Definition: error.h:35
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
void reportInternalError(const string &errorMsg)
Definition: error.cpp:29
void reportSyntaxError(const Scanner &scanner, const string &errorMsg)
Definition: error.cpp:44
void throwError(const string &errorMsg)
Definition: error.h:58
void reportError(const string &errorMsg)
Definition: error.cpp:23
#define DEFINE_EXCEPTION(NAME)
Definition: error.h:63