-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrwexception.h
46 lines (38 loc) · 1.05 KB
/
rwexception.h
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
#ifndef _rwexception_h
#define _rwexception_h
#include <exception>
#include <sstream>
#include <string>
namespace rws
{
inline void format(std::ostream&) {}
extern void raise(std::string const& error);
template <typename... Args> void raise(Args...);
//---------------------------------------------------------------------------
template <typename T, typename... Args>
void format(std::ostream& os, T const& first_arg, Args const&... args)
{
os << first_arg;
format(os, args...);
}
//---------------------------------------------------------------------------
class exception : public std::exception
{
public:
exception(std::string const& w) : m_what(w) {}
~exception() throw() {}
inline char const* what() const throw() override
{ return m_what.c_str(); }
protected:
std::string const m_what;
};
}
//-----------------------------------------------------------------------------
template <typename... Args>
void rws::raise(Args... args)
{
std::ostringstream ss;
format(ss, args...);
raise(ss.str());
}
#endif