-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception.hpp
53 lines (42 loc) · 947 Bytes
/
exception.hpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef AXIOM_EXCEPTION_HPP
#define AXIOM_EXCEPTION_HPP
#include <stdexcept>
#include <type_traits>
#include <utility>
namespace Axiom
{
struct Exception : virtual std::exception
{
public:
virtual ~Exception() {}
virtual char const* what() const noexcept override
{
return what_.c_str();
}
void set_what(std::string const & str)
{
what_ = str;
}
void set_what(std::string && str) noexcept
{
what_ = std::move(str);
}
private:
std::string what_;
};
template <typename T>
typename std::enable_if<std::is_base_of<Exception, T>::value, T>::type make_exception(std::string const & str)
{
T e;
e.set_what(str);
return e;
}
template <typename T>
typename std::enable_if<std::is_base_of<Exception, T>::value, T>::type make_exception(std::string && str) noexcept
{
T e;
e.set_what(std::move(str));
return e;
}
} //end of namespace Axiom
#endif