-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.hpp
More file actions
81 lines (60 loc) · 1.57 KB
/
errors.hpp
File metadata and controls
81 lines (60 loc) · 1.57 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef ERRORS_HPP
#define ERRORS_HPP
#include <exception>
#include <format>
#include <string>
#include <boost/exception/all.hpp>
#include <boost/stacktrace.hpp>
#include <sndfile.h>
namespace flacsplit {
struct Bad_format : std::exception {
const char *what() const noexcept override {
return "bad format";
}
};
struct Bad_samplefreq : std::exception {
const char *what() const noexcept override {
return "bad sample frequency";
}
};
struct Not_enough_samples : public std::exception {
Not_enough_samples() :
_msg("not enough samples to calculate with")
{}
Not_enough_samples(const std::string &msg) : _msg(msg) {}
const char *what() const noexcept override {
return _msg.c_str();
}
private:
std::string _msg;
};
struct Sndfile_error : std::exception {
Sndfile_error(int errnum) : errnum(errnum) {
msg = sf_error_number(errnum);
}
Sndfile_error(const std::string &msg, int errnum) : errnum(errnum) {
this->msg = std::format("{}: {}", msg, sf_error_number(errnum));
}
const char *what() const noexcept override {
return msg.c_str();
}
std::string msg;
int errnum;
};
struct Unix_error : std::exception {
Unix_error(int errnum=-1);
Unix_error(const std::string &msg, int errnum=-1);
const char *what() const noexcept override {
return msg.c_str();
}
std::string msg;
int errnum;
};
typedef boost::error_info<struct tag_stacktrace, boost::stacktrace::stacktrace> traced;
template <class E>
E throw_traced(const E &e) {
// C++23 has std::stacktrace::current().
throw boost::enable_error_info(e) << traced(boost::stacktrace::stacktrace());
}
}
#endif