2 * SPDX-License-Identifier: MIT
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>
9 #ifndef BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP
10 #define BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP
12 #include <babeltrace2/babeltrace.h>
14 #include "cfg-error-reporting.hpp"
17 * Appends a cause to the error of the current thread using the
18 * configuration `_log_cfg` and throws an instance of `_exc_cls`.
20 #define BT_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _fmt, ...) \
22 BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
26 #define BT_APPEND_CAUSE_AND_THROW(_exc_cls, _fmt, ...) \
27 BT_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _fmt, ##__VA_ARGS__)
30 * Appends a cause to the error of the current thread using the
31 * configuration `_log_cfg` and rethrows.
33 #define BT_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _fmt, ...) \
35 BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
39 #define BT_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
40 BT_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
43 * Appends a cause to the error of the current thread using the
44 * configuration `_log_cfg` and throws an instance of `_exc_cls`.
46 #define BT_APPEND_CAUSE_STR_AND_THROW_EX(_log_cfg, _exc_cls, _str) \
48 BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \
52 #define BT_APPEND_CAUSE_STR_AND_THROW(_exc_cls, _str) \
53 BT_APPEND_CAUSE_STR_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _str)
56 * Appends a cause to the error of the current thread using the
57 * configuration `_log_cfg` and rethrows.
59 #define BT_APPEND_CAUSE_STR_AND_RETHROW_EX(_log_cfg, _str) \
61 BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \
65 #define BT_APPEND_CAUSE_STR_AND_RETHROW(_str) \
66 BT_APPEND_CAUSE_STR_AND_RETHROW_EX((BT_CLOG_CFG), _str)
69 * Appends a cause with an errno message to the error of the current
70 * thread, using the initial message `_init_msg` and the configuration
71 * `_log_cfg`, and throws an instance of `_exc_cls`.
73 #define BT_APPEND_CAUSE_ERRNO_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \
75 BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
79 #define BT_APPEND_CAUSE_ERRNO_AND_THROW(_exc_cls, _init_msg, _fmt, ...) \
80 BT_APPEND_CAUSE_ERRNO_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _init_msg, _fmt, ##__VA_ARGS__)
83 * Appends a cause with an errno message to the error of the current
84 * thread, using the initial message `_init_msg` and the configuration
85 * `_log_cfg`, and rethrows.
87 #define BT_APPEND_CAUSE_ERRNO_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \
89 BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
93 #define BT_APPEND_CAUSE_ERRNO_AND_RETHROW(_init_msg, _fmt, ...) \
94 BT_APPEND_CAUSE_ERRNO_AND_RETHROW_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
96 #endif /* BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP */