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__) | |
53cd1e22 JG |
23 | |
24 | namespace lttng { | |
25 | ||
26 | namespace ctl { | |
27 | /* Wrap lttng_error_code errors which may be reported through liblttng-ctl's interface. */ | |
28 | class error : public std::runtime_error { | |
29 | public: | |
30 | explicit error(lttng_error_code error_code, | |
31 | const char *file_name, | |
32 | const char *function_name, | |
33 | unsigned int line_number); | |
34 | lttng_error_code get_code() const; | |
35 | ||
36 | private: | |
37 | lttng_error_code _error_code; | |
38 | }; | |
39 | } /* namespace ctl */ | |
40 | ||
41 | class posix_error : public std::system_error { | |
42 | public: | |
43 | explicit posix_error(const std::string &msg, | |
44 | int errno_code, | |
45 | const char *file_name, | |
46 | const char *function_name, | |
47 | unsigned int line_number); | |
48 | }; | |
49 | ||
aeeb48c6 JG |
50 | class runtime_error : public std::runtime_error { |
51 | public: | |
52 | explicit runtime_error(const std::string &msg, | |
53 | const char *file_name, | |
54 | const char *function_name, | |
55 | unsigned int line_number); | |
56 | }; | |
57 | ||
53cd1e22 JG |
58 | }; /* namespace lttng */ |
59 | ||
60 | #endif /* LTTNG_EXCEPTION_H_ */ |