congestvpn/util.hpp

22 lines
592 B
C++
Raw Normal View History

2020-06-02 13:08:23 +02:00
#pragma once
#include <exception>
#include <string>
/** MsgException -- an exception bearing a passed explanation message
*
* If `is_perror` is true, then the `strerror` corresponding message is appened
* to the message in `what()`.
*/
2020-06-02 13:08:23 +02:00
class MsgException : public std::exception {
public:
MsgException(const std::string& msg, int code=0, bool is_perror=false);
2020-06-02 13:08:23 +02:00
int errcode() const noexcept { return _code; }
const char* what() const noexcept { return _what.c_str(); };
private:
std::string _msg;
int _code;
std::string _what;
};