b7e8261ed65217f5652fd88192c37e78c178dd76
[lttng-tools.git] / src / common / exception.hpp
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__)
21 #define LTTNG_THROW_ERROR(msg) \
22 throw lttng::runtime_error(msg, __FILE__, __func__, __LINE__)
23 #define LTTNG_THROW_COMMUNICATION_ERROR(msg) \
24 throw lttng::communication_error(msg, __FILE__, __func__, __LINE__)
25 #define LTTNG_THROW_PROTOCOL_ERROR(msg) \
26 throw lttng::protocol_error(msg, __FILE__, __func__, __LINE__)
27 #define LTTNG_THROW_INVALID_ARGUMENT_ERROR(msg) \
28 throw lttng::invalid_argument_error(msg, __FILE__, __func__, __LINE__)
29
30 namespace lttng {
31 class runtime_error : public std::runtime_error {
32 public:
33 explicit runtime_error(const std::string& msg,
34 const char *file_name,
35 const char *function_name,
36 unsigned int line_number);
37 };
38
39 namespace ctl {
40 /* Wrap lttng_error_code errors which may be reported through liblttng-ctl's interface. */
41 class error : public runtime_error {
42 public:
43 explicit error(lttng_error_code error_code,
44 const char *file_name,
45 const char *function_name,
46 unsigned int line_number);
47 lttng_error_code get_code() const;
48
49 private:
50 lttng_error_code _error_code;
51 };
52 } /* namespace ctl */
53
54 class posix_error : public std::system_error {
55 public:
56 explicit posix_error(const std::string& msg,
57 int errno_code,
58 const char *file_name,
59 const char *function_name,
60 unsigned int line_number);
61 };
62
63 class communication_error : public runtime_error {
64 public:
65 explicit communication_error(const std::string& msg,
66 const char *file_name,
67 const char *function_name,
68 unsigned int line_number);
69 };
70
71 class protocol_error : public communication_error {
72 public:
73 explicit protocol_error(const std::string& msg,
74 const char *file_name,
75 const char *function_name,
76 unsigned int line_number);
77 };
78
79 class invalid_argument_error : public runtime_error {
80 public:
81 explicit invalid_argument_error(const std::string& msg,
82 const char *file_name,
83 const char *function_name,
84 unsigned int line_number);
85 };
86
87 }; /* namespace lttng */
88
89 #endif /* LTTNG_EXCEPTION_H_ */
This page took 0.031666 seconds and 4 git commands to generate.