2019-06-19 14:34:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2005 Ondra Kamenik
|
|
|
|
* Copyright © 2019 Dynare Team
|
|
|
|
*
|
|
|
|
* This file is part of Dynare.
|
|
|
|
*
|
|
|
|
* Dynare 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Dynare 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
|
2021-06-09 17:33:48 +02:00
|
|
|
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2019-06-19 14:34:30 +02:00
|
|
|
*/
|
2019-01-04 16:29:57 +01:00
|
|
|
|
|
|
|
// Exception
|
|
|
|
|
|
|
|
/* This is a simple code defining an exception and two convenience macros. */
|
|
|
|
|
2019-03-07 18:17:43 +01:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
2019-01-04 16:29:57 +01:00
|
|
|
#ifndef KORD_EXCEPTION_H
|
2019-12-20 14:36:20 +01:00
|
|
|
# define KORD_EXCEPTION_H
|
2019-01-04 16:29:57 +01:00
|
|
|
|
2019-12-20 14:36:20 +01:00
|
|
|
# define KORD_RAISE(mes) \
|
2019-01-04 16:29:57 +01:00
|
|
|
throw KordException(__FILE__, __LINE__, mes);
|
|
|
|
|
2019-12-20 14:36:20 +01:00
|
|
|
# define KORD_RAISE_IF(expr, mes) \
|
2019-01-04 16:29:57 +01:00
|
|
|
if (expr) throw KordException(__FILE__, __LINE__, mes);
|
|
|
|
|
2019-12-20 14:36:20 +01:00
|
|
|
# define KORD_RAISE_X(mes, c) \
|
2019-01-04 16:29:57 +01:00
|
|
|
throw KordException(__FILE__, __LINE__, mes, c);
|
|
|
|
|
2019-12-20 14:36:20 +01:00
|
|
|
# define KORD_RAISE_IF_X(expr, mes, c) \
|
2019-01-04 16:29:57 +01:00
|
|
|
if (expr) throw KordException(__FILE__, __LINE__, mes, c);
|
|
|
|
|
|
|
|
class KordException
|
|
|
|
{
|
|
|
|
protected:
|
2019-03-07 18:17:43 +01:00
|
|
|
std::string fname;
|
2019-01-04 16:29:57 +01:00
|
|
|
int lnum;
|
2019-03-07 18:17:43 +01:00
|
|
|
std::string message;
|
2019-01-04 16:29:57 +01:00
|
|
|
int cd;
|
|
|
|
public:
|
2019-03-07 18:17:43 +01:00
|
|
|
KordException(std::string f, int l, std::string mes, int c = 255)
|
|
|
|
: fname{std::move(f)}, lnum{l}, message{std::move(mes)}, cd{c}
|
2019-01-04 16:29:57 +01:00
|
|
|
{
|
|
|
|
}
|
2019-03-07 18:17:43 +01:00
|
|
|
virtual ~KordException() = default;
|
2019-01-04 16:29:57 +01:00
|
|
|
virtual void
|
|
|
|
print() const
|
|
|
|
{
|
2019-03-07 18:17:43 +01:00
|
|
|
std::cout << "At " << fname << ':' << lnum << ":(" << cd << "):" << message << '\n';
|
2019-01-04 16:29:57 +01:00
|
|
|
}
|
|
|
|
virtual int
|
|
|
|
code() const
|
|
|
|
{
|
|
|
|
return cd;
|
|
|
|
}
|
2019-03-07 18:17:43 +01:00
|
|
|
const std::string &
|
2019-01-04 16:29:57 +01:00
|
|
|
get_message() const
|
|
|
|
{
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-11 16:45:09 +02:00
|
|
|
// KordException error code definitions
|
2019-03-07 18:17:43 +01:00
|
|
|
constexpr int KORD_FP_NOT_CONV = 254;
|
|
|
|
constexpr int KORD_FP_NOT_FINITE = 253;
|
|
|
|
constexpr int KORD_MD_NOT_STABLE = 252;
|
2019-01-04 16:29:57 +01:00
|
|
|
|
|
|
|
#endif
|