55a3f98185bf9bc4a701eaf842010e8bba6ef552
[babeltrace.git] / src / cpp-common / cfg-logging-error-reporting-throw.hpp
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>
13 #include "cfg-logging-error-reporting.hpp"
14
15 /*
16 * Logs with the error level using the configuration `_log_cfg`, appends
17 * a cause to the error of the current thread, and throws an instance of
18 * `_exc_cls`.
19 */
20 #define BT_CLOGE_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _fmt, ...) \
21 do { \
22 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
23 throw _exc_cls {}; \
24 } while (false)
25
26 #define BT_CLOGE_APPEND_CAUSE_AND_THROW(_exc_cls, _fmt, ...) \
27 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _fmt, ##__VA_ARGS__)
28
29 /*
30 * Logs with the error level using the configuration `_log_cfg`, appends
31 * a cause to the error of the current thread, and rethrows.
32 */
33 #define BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _fmt, ...) \
34 do { \
35 BT_CLOGE_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
36 throw; \
37 } while (false)
38
39 #define BT_CLOGE_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
40 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
41
42 /*
43 * Logs with the error level using the configuration `_log_cfg`, appends
44 * a cause to the error of the current thread, and throws an instance of
45 * `_exc_cls`.
46 */
47 #define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _str) \
48 do { \
49 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
50 throw _exc_cls {}; \
51 } while (false)
52
53 #define BT_CLOGE_STR_APPEND_CAUSE_AND_THROW(_exc_cls, _str) \
54 BT_CLOGE_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _str)
55
56 /*
57 * Logs with the error level using the configuration `_log_cfg`, appends
58 * a cause to the error of the current thread, and rethrows.
59 */
60 #define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _str) \
61 do { \
62 BT_CLOGE_STR_APPEND_CAUSE_EX((_log_cfg), _str); \
63 throw; \
64 } while (false)
65
66 #define BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW(_str) \
67 BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _str)
68
69 /*
70 * Logs an errno message with the error level, using the configuration
71 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
72 * to the error of the current thread, and throws an instance of
73 * `_exc_cls`.
74 */
75 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \
76 do { \
77 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
78 throw _exc_cls {}; \
79 } while (false)
80
81 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW(_exc_cls, _init_msg, _fmt, ...) \
82 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _init_msg, _fmt, \
83 ##__VA_ARGS__)
84
85 /*
86 * Logs an errno message with the error level, using the configuration
87 * `_log_cfg`, having the initial message `_init_msg`, appends a cause
88 * to the error of the current thread, and rethrows.
89 */
90 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \
91 do { \
92 BT_CLOGE_ERRNO_APPEND_CAUSE_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
93 throw; \
94 } while (false)
95
96 #define BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW(_init_msg, _fmt, ...) \
97 BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
98
99 /*
100 * Logs memory bytes with the error level using the configuration
101 * `_log_cfg`, appends a cause to the error of the current thread, and
102 * throws an instance of `_exc_cls`.
103 */
104 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _data, _data_sz, _fmt, ...) \
105 do { \
106 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
107 throw _exc_cls {}; \
108 } while (false)
109
110 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW(_exc_cls, _data, _data_sz, _fmt, ...) \
111 BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, (_data), (_data_sz), _fmt, \
112 ##__VA_ARGS__)
113
114 /*
115 * Logs memory bytes with the error level using the configuration
116 * `_log_cfg`, appends a cause to the error of the current thread, and
117 * rethrows.
118 */
119 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _data, _data_sz, _fmt, ...) \
120 do { \
121 BT_CLOGE_MEM_APPEND_CAUSE_EX((_log_cfg), (_data), (_data_sz), _fmt, ##__VA_ARGS__); \
122 throw; \
123 } while (false)
124
125 #define BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW(_data, _data_sz, _fmt, ...) \
126 BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), (_data), (_data_sz), _fmt, \
127 ##__VA_ARGS__)
128
129 #endif /* BABELTRACE_CPP_COMMON_CFG_LOGGING_ERROR_REPORTING_THROW_HPP */
This page took 0.032269 seconds and 3 git commands to generate.