errors.hpp 644 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef RTG_GUARD_ERRORS_HPP
#define RTG_GUARD_ERRORS_HPP

#include <exception>
#include <stdexcept>
#include <string>

namespace rtg {

struct exception : std::runtime_error
{
    exception(std::string msg = "")
    : std::runtime_error(msg)
    {}
};

inline exception make_exception(std::string context, std::string message = "")
{
    return {context + ": " + message};
}

inline std::string make_source_context(const std::string& file, int line)
{
    return file + ":" + std::to_string(line);
}

#define RTG_THROW(...) \
    throw rtg::make_exception(rtg::make_source_context(__FILE__, __LINE__), __VA_ARGS__)

} // namespace rtg

#endif