File: errors.hpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (34 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (2)
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
#pragma once

#include <cerrno>
#include <cstring>
#include <stdexcept>

#include "common.hpp"

POLYBAR_NS

using std::exception;
using std::runtime_error;
using std::strerror;

class application_error : public runtime_error {
 public:
  explicit application_error(const string& message, int code = 0) : runtime_error(message), code(code) {}
  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) {}
};

#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