Sort includes in C++ files
[babeltrace.git] / src / cpp-common / cfg-logging-error-reporting-throw.hpp
CommitLineData
b4953462
SM
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
5 * Copyright (c) 2022 Simon Marchi <simon.marchi@efficios.com>
6 * Copyright (c) 2022 Philippe Proulx <eeppeliteloop@gmail.com>
7 */
8
9#ifndef BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP
10#define BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP
11
12#include <babeltrace2/babeltrace.h>
c802cacb 13
b4953462
SM
14#include "cfg-logging-error-reporting.hpp"
15
16/*
17 * Logs with the error level using the configuration `_log_cfg`, appends
18 * a cause to the error of the current thread, and throws an instance of
19 * `_exc_cls`.
20 */
21#define BT_CLOGE_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _fmt, ...) \
22 do { \
23 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
24 throw _exc_cls {}; \
25 } while (false)
26
27#define BT_CLOGE_APPEND_CAUSE_AND_THROW(_exc_cls, _fmt, ...) \
28 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _fmt, ##__VA_ARGS__)
29
30/*
31 * Logs with the error level using the configuration `_log_cfg`, appends
32 * a cause to the error of the current thread, and rethrows.
33 */
34#define BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _fmt, ...) \
35 do { \
36 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
37 throw; \
38 } while (false)
39
40#define BT_CLOGE_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
41 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
42
43/*
44 * Logs with the error level using the configuration `_log_cfg`, appends
45 * a cause to the error of the current thread, and throws an instance of
46 * `_exc_cls`.
47 */
48#define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _str) \
49 do { \
50 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
51 throw _exc_cls {}; \
52 } while (false)
53
54#define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW(_exc_cls, _str) \
55 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _str)
56
57/*
58 * Logs with the error level using the configuration `_log_cfg`, appends
59 * a cause to the error of the current thread, and rethrows.
60 */
61#define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _str) \
62 do { \
63 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
64 throw; \
65 } while (false)
66
67#define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW(_str) \
68 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _str)
69
70/*
71 * Logs an errno message with the error level, using the configuration
72 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
73 * to the error of the current thread, and throws an instance of
74 * `_exc_cls`.
75 */
76#define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \
77 do { \
78 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
79 throw _exc_cls {}; \
80 } while (false)
81
82#define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW(_exc_cls, _init_msg, _fmt, ...) \
83 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _init_msg, _fmt, \
84 ##__VA_ARGS__)
85
86/*
87 * Logs an errno message with the error level, using the configuration
88 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
89 * to the error of the current thread, and rethrows.
90 */
91#define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \
92 do { \
93 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
94 throw; \
95 } while (false)
96
97#define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW(_init_msg, _fmt, ...) \
98 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
99
100/*
101 * Logs memory bytes with the error level using the configuration
102 * `_log_cfg`, appends a cause to the error of the current thread, and
103 * throws an instance of `_exc_cls`.
104 */
105#define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _data, _data_sz, _fmt, ...) \
106 do { \
107 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
108 throw _exc_cls {}; \
109 } while (false)
110
111#define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW(_exc_cls, _data, _data_sz, _fmt, ...) \
112 BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, (_data), (_data_sz), _fmt, \
113 ##__VA_ARGS__)
114
115/*
116 * Logs memory bytes with the error level using the configuration
117 * `_log_cfg`, appends a cause to the error of the current thread, and
118 * rethrows.
119 */
120#define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
121 do { \
122 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
123 throw; \
124 } while (false)
125
126#define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW(_data, _data_sz, _fmt, ...) \
127 BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), (_data), (_data_sz), _fmt, \
128 ##__VA_ARGS__)
129
130#endif /* BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP */
This page took 0.029206 seconds and 4 git commands to generate.