Commit | Line | Data |
---|---|---|
53cd1e22 JG |
1 | /* |
2 | * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #ifndef LTTNG_EXCEPTION_H_ | |
9 | #define LTTNG_EXCEPTION_H_ | |
10 | ||
11 | #include <string> | |
12 | #include <stdexcept> | |
13 | #include <system_error> | |
14 | ||
15 | #include <lttng/lttng-error.h> | |
16 | ||
17 | #define LTTNG_THROW_CTL(error_code) \ | |
18 | throw lttng::ctl::error(msg, error_code, __FILE__, __func__, __LINE__) | |
19 | #define LTTNG_THROW_POSIX(msg, errno_code) \ | |
20 | throw lttng::posix_error(msg, errno_code, __FILE__, __func__, __LINE__) | |
aeeb48c6 JG |
21 | #define LTTNG_THROW_ERROR(msg) \ |
22 | throw lttng::runtime_error(msg, __FILE__, __func__, __LINE__) | |
b6bbb1d6 JG |
23 | #define LTTNG_THROW_UNSUPPORTED_ERROR(msg) \ |
24 | throw lttng::runtime_error(msg, __FILE__, __func__, __LINE__) | |
baac5795 JG |
25 | #define LTTNG_THROW_COMMUNICATION_ERROR(msg) \ |
26 | throw lttng::communication_error(msg, __FILE__, __func__, __LINE__) | |
27 | #define LTTNG_THROW_PROTOCOL_ERROR(msg) \ | |
28 | throw lttng::protocol_error(msg, __FILE__, __func__, __LINE__) | |
29 | #define LTTNG_THROW_INVALID_ARGUMENT_ERROR(msg) \ | |
30 | throw lttng::invalid_argument_error(msg, __FILE__, __func__, __LINE__) | |
53cd1e22 JG |
31 | |
32 | namespace lttng { | |
baac5795 JG |
33 | class runtime_error : public std::runtime_error { |
34 | public: | |
35 | explicit runtime_error(const std::string& msg, | |
36 | const char *file_name, | |
37 | const char *function_name, | |
38 | unsigned int line_number); | |
39 | }; | |
53cd1e22 | 40 | |
b6bbb1d6 JG |
41 | class unsupported_error : public std::runtime_error { |
42 | public: | |
43 | explicit unsupported_error(const std::string& msg, | |
44 | const char *file_name, | |
45 | const char *function_name, | |
46 | unsigned int line_number); | |
47 | }; | |
48 | ||
53cd1e22 JG |
49 | namespace ctl { |
50 | /* Wrap lttng_error_code errors which may be reported through liblttng-ctl's interface. */ | |
baac5795 | 51 | class error : public runtime_error { |
53cd1e22 JG |
52 | public: |
53 | explicit error(lttng_error_code error_code, | |
baac5795 JG |
54 | const char *file_name, |
55 | const char *function_name, | |
56 | unsigned int line_number); | |
53cd1e22 JG |
57 | lttng_error_code get_code() const; |
58 | ||
59 | private: | |
60 | lttng_error_code _error_code; | |
61 | }; | |
62 | } /* namespace ctl */ | |
63 | ||
64 | class posix_error : public std::system_error { | |
65 | public: | |
baac5795 JG |
66 | explicit posix_error(const std::string& msg, |
67 | int errno_code, | |
68 | const char *file_name, | |
69 | const char *function_name, | |
70 | unsigned int line_number); | |
53cd1e22 JG |
71 | }; |
72 | ||
baac5795 JG |
73 | class communication_error : public runtime_error { |
74 | public: | |
75 | explicit communication_error(const std::string& msg, | |
76 | const char *file_name, | |
77 | const char *function_name, | |
78 | unsigned int line_number); | |
79 | }; | |
80 | ||
81 | class protocol_error : public communication_error { | |
82 | public: | |
83 | explicit protocol_error(const std::string& msg, | |
84 | const char *file_name, | |
85 | const char *function_name, | |
86 | unsigned int line_number); | |
87 | }; | |
88 | ||
89 | class invalid_argument_error : public runtime_error { | |
aeeb48c6 | 90 | public: |
baac5795 JG |
91 | explicit invalid_argument_error(const std::string& msg, |
92 | const char *file_name, | |
93 | const char *function_name, | |
94 | unsigned int line_number); | |
aeeb48c6 JG |
95 | }; |
96 | ||
53cd1e22 JG |
97 | }; /* namespace lttng */ |
98 | ||
99 | #endif /* LTTNG_EXCEPTION_H_ */ |