Remove some unused includes in C++ files
[babeltrace.git] / src / cpp-common / cfg-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_ERROR_REPORTING_THROW_HPP
10#define BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP
11
12#include <babeltrace2/babeltrace.h>
c802cacb 13
b4953462
SM
14#include "cfg-error-reporting.hpp"
15
16/*
17 * Appends a cause to the error of the current thread using the
18 * configuration `_log_cfg` and throws an instance of `_exc_cls`.
19 */
20#define BT_APPEND_CAUSE_AND_THROW_EX(_log_cfg, _exc_cls, _fmt, ...) \
21 do { \
22 BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
23 throw _exc_cls {}; \
24 } while (false)
25
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__)
28
29/*
30 * Appends a cause to the error of the current thread using the
31 * configuration `_log_cfg` and rethrows.
32 */
33#define BT_APPEND_CAUSE_AND_RETHROW_EX(_log_cfg, _fmt, ...) \
34 do { \
35 BT_APPEND_CAUSE_EX((_log_cfg), _fmt, ##__VA_ARGS__); \
c7e1be4b
SM
36 throw; \
37 } while (false)
b4953462
SM
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 */
This page took 0.027958 seconds and 4 git commands to generate.