2019-01-04 16:29:57 +01:00
|
|
|
// Copyright 2005, Ondra Kamenik
|
|
|
|
|
|
|
|
// 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
|
|
|
|
#define KORD_EXCEPTION_H
|
|
|
|
|
|
|
|
#define KORD_RAISE(mes) \
|
|
|
|
throw KordException(__FILE__, __LINE__, mes);
|
|
|
|
|
|
|
|
#define KORD_RAISE_IF(expr, mes) \
|
|
|
|
if (expr) throw KordException(__FILE__, __LINE__, mes);
|
|
|
|
|
|
|
|
#define KORD_RAISE_X(mes, c) \
|
|
|
|
throw KordException(__FILE__, __LINE__, mes, c);
|
|
|
|
|
|
|
|
#define KORD_RAISE_IF_X(expr, mes, c) \
|
|
|
|
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
|