2020-06-02 13:08:23 +02:00
|
|
|
#include <cstdio>
|
2020-06-03 14:54:01 +02:00
|
|
|
#include <string.h>
|
2020-06-02 13:08:23 +02:00
|
|
|
|
|
|
|
#include "util.hpp"
|
|
|
|
|
2020-06-03 14:54:01 +02:00
|
|
|
MsgException::MsgException(const std::string& msg, int code, bool is_perror)
|
2020-06-02 13:08:23 +02:00
|
|
|
: _msg(msg), _code(code)
|
|
|
|
{
|
|
|
|
_what = _msg;
|
|
|
|
|
|
|
|
if(_code != 0) {
|
2020-06-03 14:54:01 +02:00
|
|
|
if(is_perror) {
|
|
|
|
_what += ": ";
|
|
|
|
_what += strerror(errno);
|
|
|
|
}
|
|
|
|
|
2020-06-02 13:08:23 +02:00
|
|
|
char remainder[20];
|
|
|
|
sprintf(remainder, " (code %d)", _code);
|
|
|
|
_what += remainder;
|
|
|
|
}
|
|
|
|
}
|