Add basic exception types and throwing facilities
[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
22 namespace lttng {
23
24 namespace ctl {
25 /* Wrap lttng_error_code errors which may be reported through liblttng-ctl's interface. */
26 class error : public std::runtime_error {
27 public:
28 explicit error(lttng_error_code error_code,
29 const char *file_name,
30 const char *function_name,
31 unsigned int line_number);
32 lttng_error_code get_code() const;
33
34 private:
35 lttng_error_code _error_code;
36 };
37 } /* namespace ctl */
38
39 class posix_error : public std::system_error {
40 public:
41 explicit posix_error(const std::string &msg,
42 int errno_code,
43 const char *file_name,
44 const char *function_name,
45 unsigned int line_number);
46 };
47
48 }; /* namespace lttng */
49
50 #endif /* LTTNG_EXCEPTION_H_ */
This page took 0.036614 seconds and 4 git commands to generate.