error.h
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#ifndef ERROR_GUARD
#define ERROR_GUARD
#include <stdexcept>
#include <string>
class Scanner;
class FrobbyException : public std::runtime_error {
public:
FrobbyException(const string& str): runtime_error(str) {}
};
class InternalFrobbyException : public std::logic_error {
public:
InternalFrobbyException(const string& str): logic_error(str) {}
};
// The do {...} while (0) is to collect everything into a single
// statement that still requires a semicolon after it. The throw is to
// prevent spurious compiler warnings about a missing return
// statement.
#define INTERNAL_ERROR(msg) \
do { \
reportInternalError(msg, __FILE__, __LINE__); \
throw; \
} while (false)
#define INTERNAL_ERROR_UNIMPLEMENTED() \
INTERNAL_ERROR("Called function that has not been implemented.")
// These methods throw exceptions.
void reportError(const string& errorMsg);
void reportInternalError(const string& errorMsg);
void reportInternalError
(const string& errorMsg, const char* file, unsigned int lineNumber);
void reportSyntaxError(const Scanner& scanner, const string& errorMsg);
template<class Exception>
void throwError(const string& errorMsg) {
throw Exception("ERROR: " + errorMsg + '\n');
}
#define DEFINE_EXCEPTION(NAME) \
class NAME##Exception : public FrobbyException { \
public: \
NAME##Exception(const string& str): FrobbyException(str) {} \
}
DEFINE_EXCEPTION(UnknownName);
DEFINE_EXCEPTION(AmbiguousName);
DEFINE_EXCEPTION(Unsupported);
#endif
FrobbyException::FrobbyException
FrobbyException(const string &str)
Definition error.h:29
InternalFrobbyException::InternalFrobbyException
InternalFrobbyException(const string &str)
Definition error.h:35
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
reportInternalError
void reportInternalError(const string &errorMsg)
Definition error.cpp:29
reportSyntaxError
void reportSyntaxError(const Scanner &scanner, const string &errorMsg)
Definition error.cpp:44
throwError
void throwError(const string &errorMsg)
Definition error.h:58
reportError
void reportError(const string &errorMsg)
Definition error.cpp:23
DEFINE_EXCEPTION
#define DEFINE_EXCEPTION(NAME)
Definition error.h:63