16#ifndef OPENVPN_COMMON_EXCEPTION_H
17#define OPENVPN_COMMON_EXCEPTION_H
27#ifdef OPENVPN_DEBUG_EXCEPTION
29#define OPENVPN_FILE_LINE "/" __FILE__ ":" OPENVPN_STRINGIZE(__LINE__)
31#define OPENVPN_FILE_LINE
48 const char *
what() const noexcept
override
52 const std::string &
err() const noexcept
65 const std::string head = label +
": ";
75#define OPENVPN_SIMPLE_EXCEPTION(C) \
76 class C : public std::exception \
79 const char *what() const noexcept override \
81 return #C OPENVPN_FILE_LINE; \
86#define OPENVPN_SIMPLE_EXCEPTION_INHERIT(B, C) \
90 C() : B(#C OPENVPN_FILE_LINE) \
93 const char *what() const noexcept override \
95 return #C OPENVPN_FILE_LINE; \
100#define OPENVPN_EXCEPTION(C) \
101 class C : public openvpn::Exception \
104 C() : openvpn::Exception(#C OPENVPN_FILE_LINE) \
107 C(const std::string err) : openvpn::Exception(#C OPENVPN_FILE_LINE ": " + err) \
113#define OPENVPN_EXCEPTION_WITH_CODE(C, DEFAULT_CODE, ...) \
114 enum C##_##code : unsigned int{__VA_ARGS__}; \
115 class C : public openvpn::Exception \
118 C() : openvpn::Exception(#C OPENVPN_FILE_LINE) \
120 add_label(#DEFAULT_CODE); \
122 C(const std::string &err) : openvpn::Exception(#C OPENVPN_FILE_LINE ": " + err) \
124 add_label(#DEFAULT_CODE); \
126 option_error(C##_##code code, const std::string &err) \
127 : openvpn::Exception(#C OPENVPN_FILE_LINE ": " + err) \
129 add_label(code2string(code)); \
131 static std::string code2string(C##_##code code); \
134#define OPENVPN_UNTAGGED_EXCEPTION(C) \
135 class C : public openvpn::Exception \
138 C(const std::string err) : openvpn::Exception(err) \
144#define OPENVPN_EXCEPTION_INHERIT(B, C) \
148 C() : B(#C OPENVPN_FILE_LINE) \
151 C(const std::string err) : B(#C OPENVPN_FILE_LINE ": " + err) \
158#define OPENVPN_UNTAGGED_EXCEPTION_INHERIT(B, C) \
166#define OPENVPN_THROW_EXCEPTION(stuff) \
169 std::ostringstream _ovpn_exc; \
170 _ovpn_exc << stuff; \
171 throw openvpn::Exception(_ovpn_exc.str()); \
175#define OPENVPN_THROW(exc, stuff) \
178 std::ostringstream _ovpn_exc; \
179 _ovpn_exc << stuff; \
180 throw exc(_ovpn_exc.str()); \
183#define OPENVPN_THROW_ARG1(exc, arg, stuff) \
186 std::ostringstream _ovpn_exc; \
187 _ovpn_exc << stuff; \
188 throw exc(arg, _ovpn_exc.str()); \
Exception(const std::string &err) noexcept
const std::string & err() const noexcept
const char * what() const noexcept override
virtual ~Exception() noexcept=default
Exception(std::string &&err) noexcept
void remove_label(const std::string &label)
void add_label(const std::string &label)
bool starts_with(const STRING &str, const std::string &prefix)
Support deferred server-side state creation when client connects.
void throw_ref(const std::exception &e)