dynare/dynare++/utils/cc/exception.hh

51 lines
846 B
C++
Raw Normal View History

// Copyright (C) 2005, Ondra Kamenik
// $Id: exception.h 1367 2007-07-11 14:21:57Z kamenik $
#ifndef OGU_EXCEPTION_H
#define OGU_EXCEPTION_H
#include <string>
2019-01-10 18:24:04 +01:00
#include <iostream>
#include <utility>
2017-05-16 16:30:27 +02:00
namespace ogu
{
/** A primitive exception. */
class Exception
{
protected:
2019-01-10 18:24:04 +01:00
const std::string file;
const int line;
const std::string mes;
2017-05-16 16:30:27 +02:00
public:
2019-01-10 18:24:04 +01:00
Exception(std::string file_arg, int line_arg, std::string mes_arg)
: file{std::move(file_arg)},
line{line_arg},
mes{std::move(mes_arg)}
2017-05-16 16:30:27 +02:00
{
}
2019-01-10 18:24:04 +01:00
virtual ~Exception() = default;
2017-05-16 16:30:27 +02:00
void
2019-01-10 18:24:04 +01:00
print(std::ostream &out) const
2017-05-16 16:30:27 +02:00
{
2019-01-10 18:24:04 +01:00
out << file << ':' << line << ": " << mes << std::endl;
2017-05-16 16:30:27 +02:00
}
2019-01-10 18:24:04 +01:00
2017-05-16 16:30:27 +02:00
void
print() const
{
2019-01-10 18:24:04 +01:00
print(std::cout);
2017-05-16 16:30:27 +02:00
}
2019-01-10 18:24:04 +01:00
std::string
2017-05-16 16:30:27 +02:00
message() const
{
return mes;
}
};
};
#endif