| 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_ERROR_REPORTING_THROW_HPP |
| 10 | #define BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP |
| 11 | |
| 12 | #include <babeltrace2/babeltrace.h> |
| 13 | #include "cfg-error-reporting.hpp" |
| 14 | |
| 15 | /* |
| 16 | * Appends a cause to the error of the current thread using the |
| 17 | * configuration `_log_cfg` and throws an instance of `_exc_cls`. |
| 18 | */ |
| 19 | #define BT_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _fmt, ...) \ |
| 20 | do { \ |
| 21 | BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \ |
| 22 | throw _exc_cls {}; \ |
| 23 | } while (false) |
| 24 | |
| 25 | #define BT_APPEND_CAUSE_AND_THROW(_exc_cls, _fmt, ...) \ |
| 26 | BT_APPEND_CAUSE_AND_THROW_EX((BT_CLOG_CFG), _exc_cls, _fmt, ##__VA_ARGS__) |
| 27 | |
| 28 | /* |
| 29 | * Appends a cause to the error of the current thread using the |
| 30 | * configuration `_log_cfg` and rethrows. |
| 31 | */ |
| 32 | #define BT_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _fmt, ...) \ |
| 33 | do { \ |
| 34 | BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \ |
| 35 | throw; |
| 36 | } |
| 37 | while (false) |
| 38 | |
| 39 | #define BT_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \ |
| 40 | BT_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__) |
| 41 | |
| 42 | /* |
| 43 | * Appends a cause to the error of the current thread using the |
| 44 | * configuration `_log_cfg` and throws an instance of `_exc_cls`. |
| 45 | */ |
| 46 | #define BT_APPEND_CAUSE_STR_AND_THROW_EX(_log_cfg, _exc_cls, _str) \ |
| 47 | do { \ |
| 48 | BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \ |
| 49 | throw _exc_cls {}; \ |
| 50 | } while (false) |
| 51 | |
| 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) |
| 54 | |
| 55 | /* |
| 56 | * Appends a cause to the error of the current thread using the |
| 57 | * configuration `_log_cfg` and rethrows. |
| 58 | */ |
| 59 | #define BT_APPEND_CAUSE_STR_AND_RETHROW_EX(_log_cfg, _str) \ |
| 60 | do { \ |
| 61 | BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \ |
| 62 | throw; \ |
| 63 | } while (false) |
| 64 | |
| 65 | #define BT_APPEND_CAUSE_STR_AND_RETHROW(_str) \ |
| 66 | BT_APPEND_CAUSE_STR_AND_RETHROW_EX((BT_CLOG_CFG), _str) |
| 67 | |
| 68 | /* |
| 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`. |
| 72 | */ |
| 73 | #define BT_APPEND_CAUSE_ERRNO_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \ |
| 74 | do { \ |
| 75 | BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \ |
| 76 | throw _exc_cls {}; \ |
| 77 | } while (false) |
| 78 | |
| 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__) |
| 81 | |
| 82 | /* |
| 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. |
| 86 | */ |
| 87 | #define BT_APPEND_CAUSE_ERRNO_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \ |
| 88 | do { \ |
| 89 | BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \ |
| 90 | throw; \ |
| 91 | } while (false) |
| 92 | |
| 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__) |
| 95 | |
| 96 | #endif /* BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP */ |