-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxerror.h
35 lines (24 loc) · 889 Bytes
/
xerror.h
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
35
#pragma once
#if defined(USE_EXCEPTIONS)
#include <exception>
#include <string>
#include <errno.h>
class Exception : public std::exception {
std::string msg;
public:
Exception(const std::string &newMsg) : msg(newMsg) {
}
virtual const char* what() const noexcept {
return msg.c_str();
}
}; // Exception
#define ERROR(msg...) {std::ostringstream __ss__; __ss__ << msg; throw Exception(__ss__.str());}
#else // no exceptions
#include <cstdlib>
#include <iostream>
#include <rang.hpp>
#define ERROR(msg...) {std::cerr << ::rang::fg::red << msg << ::rang::style::reset << std::endl; std::exit(1);}
#endif
// syscall failure reporting
#define ERROR_SYSCALL(syscall) ERROR("system call '" << #syscall << "' failed: " << strerror(errno))
#define ERROR_SYSCALL1(syscall, details...) ERROR("system call '" << #syscall << "' failed: " << strerror(errno) << ": " << details)