2016-11-25 12:55:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cerrno>
|
2016-12-05 19:41:00 +00:00
|
|
|
#include <cstring>
|
2019-12-24 19:47:49 +00:00
|
|
|
#include <stdexcept>
|
2016-11-25 12:55:15 +00:00
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
using std::strerror;
|
|
|
|
using std::exception;
|
|
|
|
using std::runtime_error;
|
|
|
|
|
|
|
|
class application_error : public runtime_error {
|
|
|
|
public:
|
|
|
|
explicit application_error(const string& message, int code = 0) : runtime_error(message), code(code) {}
|
2016-12-20 04:05:43 +00:00
|
|
|
virtual ~application_error() {}
|
2016-11-25 12:55:15 +00:00
|
|
|
int code{0};
|
|
|
|
};
|
|
|
|
|
|
|
|
class system_error : public application_error {
|
|
|
|
public:
|
|
|
|
explicit system_error() : application_error(strerror(errno), errno) {}
|
|
|
|
explicit system_error(const string& message)
|
|
|
|
: application_error(message + " (reason: " + strerror(errno) + ")", errno) {}
|
2016-12-20 04:05:43 +00:00
|
|
|
virtual ~system_error() {}
|
2016-11-25 12:55:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFINE_CHILD_ERROR(error, parent) \
|
|
|
|
class error : public parent { \
|
|
|
|
using parent::parent; \
|
|
|
|
}
|
|
|
|
#define DEFINE_ERROR(error) DEFINE_CHILD_ERROR(error, application_error)
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|