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__); \
40 #define BT_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
41 BT_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
44 * Appends a cause to the error of the current thread using the
45 * configuration `_log_cfg` and throws an instance of `_exc_cls`.
47 #define BT_APPEND_CAUSE_STR_AND_THROW_EX(_log_cfg, _exc_cls, _str) \
49 BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \
53 #define BT_APPEND_CAUSE_STR_AND_THROW(_exc_cls, _str) \
54 BT_APPEND_CAUSE_STR_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _str)
57 * Appends a cause to the error of the current thread using the
58 * configuration `_log_cfg` and rethrows.
60 #define BT_APPEND_CAUSE_STR_AND_RETHROW_EX(_log_cfg, _str) \
62 BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \
66 #define BT_APPEND_CAUSE_STR_AND_RETHROW(_str) \
67 BT_APPEND_CAUSE_STR_AND_RETHROW_EX((BT_CLOG_CFG), _str)
70 * Appends a cause with an errno message to the error of the current
71 * thread, using the initial message `_init_msg` and the configuration
72 * `_log_cfg`, and throws an instance of `_exc_cls`.
74 #define BT_APPEND_CAUSE_ERRNO_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \
76 BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
80 #define BT_APPEND_CAUSE_ERRNO_AND_THROW(_exc_cls, _init_msg, _fmt, ...) \
81 BT_APPEND_CAUSE_ERRNO_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _init_msg, _fmt, ##__VA_ARGS__)
84 * Appends a cause with an errno message to the error of the current
85 * thread, using the initial message `_init_msg` and the configuration
86 * `_log_cfg`, and rethrows.
88 #define BT_APPEND_CAUSE_ERRNO_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \
90 BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
94 #define BT_APPEND_CAUSE_ERRNO_AND_RETHROW(_init_msg, _fmt, ...) \
95 BT_APPEND_CAUSE_ERRNO_AND_RETHROW_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__)
97 #endif /* BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP */