tests: Use `--no-wait` when destroying sessions in relayd-grouping
[lttng-tools.git] / src / common / exception.hpp
CommitLineData
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
28f23191
JG
11#include <lttng/lttng-error.h>
12
53cd1e22 13#include <stdexcept>
28f23191 14#include <string>
53cd1e22
JG
15#include <system_error>
16
0038180d 17#define LTTNG_THROW_CTL(msg, error_code) \
53cd1e22
JG
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__)
0038180d 21#define LTTNG_THROW_ERROR(msg) throw lttng::runtime_error(msg, __FILE__, __func__, __LINE__)
b6bbb1d6
JG
22#define LTTNG_THROW_UNSUPPORTED_ERROR(msg) \
23 throw lttng::runtime_error(msg, __FILE__, __func__, __LINE__)
baac5795
JG
24#define LTTNG_THROW_COMMUNICATION_ERROR(msg) \
25 throw lttng::communication_error(msg, __FILE__, __func__, __LINE__)
26#define LTTNG_THROW_PROTOCOL_ERROR(msg) \
27 throw lttng::protocol_error(msg, __FILE__, __func__, __LINE__)
28#define LTTNG_THROW_INVALID_ARGUMENT_ERROR(msg) \
29 throw lttng::invalid_argument_error(msg, __FILE__, __func__, __LINE__)
53cd1e22
JG
30
31namespace lttng {
baac5795
JG
32class runtime_error : public std::runtime_error {
33public:
34 explicit runtime_error(const std::string& msg,
28f23191
JG
35 const char *file_name,
36 const char *function_name,
37 unsigned int line_number);
baac5795 38};
53cd1e22 39
b6bbb1d6
JG
40class unsupported_error : public std::runtime_error {
41public:
42 explicit unsupported_error(const std::string& msg,
28f23191
JG
43 const char *file_name,
44 const char *function_name,
45 unsigned int line_number);
b6bbb1d6
JG
46};
47
53cd1e22
JG
48namespace ctl {
49/* Wrap lttng_error_code errors which may be reported through liblttng-ctl's interface. */
baac5795 50class error : public runtime_error {
53cd1e22 51public:
0038180d
JG
52 explicit error(const std::string& msg,
53 lttng_error_code error_code,
54 const char *file_name,
55 const char *function_name,
56 unsigned int line_number);
20f5a9ae
JG
57
58 lttng_error_code code() const noexcept
59 {
60 return _error_code;
61 }
53cd1e22
JG
62
63private:
20f5a9ae 64 const lttng_error_code _error_code;
53cd1e22
JG
65};
66} /* namespace ctl */
67
68class posix_error : public std::system_error {
69public:
baac5795 70 explicit posix_error(const std::string& msg,
28f23191
JG
71 int errno_code,
72 const char *file_name,
73 const char *function_name,
74 unsigned int line_number);
53cd1e22
JG
75};
76
baac5795
JG
77class communication_error : public runtime_error {
78public:
79 explicit communication_error(const std::string& msg,
28f23191
JG
80 const char *file_name,
81 const char *function_name,
82 unsigned int line_number);
baac5795
JG
83};
84
85class protocol_error : public communication_error {
86public:
87 explicit protocol_error(const std::string& msg,
28f23191
JG
88 const char *file_name,
89 const char *function_name,
90 unsigned int line_number);
baac5795
JG
91};
92
93class invalid_argument_error : public runtime_error {
aeeb48c6 94public:
baac5795 95 explicit invalid_argument_error(const std::string& msg,
28f23191
JG
96 const char *file_name,
97 const char *function_name,
98 unsigned int line_number);
aeeb48c6
JG
99};
100
53cd1e22
JG
101}; /* namespace lttng */
102
103#endif /* LTTNG_EXCEPTION_H_ */
This page took 0.040956 seconds and 4 git commands to generate.