Sort 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__); \
36 throw;
37}
38while (false)
39
40#define BT_APPEND_CAUSE_AND_RETHROW(_fmt, ...) \
41 BT_APPEND_CAUSE_AND_RETHROW_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__)
42
43/*
44 * Appends a cause to the error of the current thread using the
45 * configuration `_log_cfg` and throws an instance of `_exc_cls`.
46 */
47#define BT_APPEND_CAUSE_STR_AND_THROW_EX(_log_cfg, _exc_cls, _str) \
48 do { \
49 BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \
50 throw _exc_cls {}; \
51 } while (false)
52
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)
55
56/*
57 * Appends a cause to the error of the current thread using the
58 * configuration `_log_cfg` and rethrows.
59 */
60#define BT_APPEND_CAUSE_STR_AND_RETHROW_EX(_log_cfg, _str) \
61 do { \
62 BT_APPEND_CAUSE_STR_EX((_log_cfg), _str); \
63 throw; \
64 } while (false)
65
66#define BT_APPEND_CAUSE_STR_AND_RETHROW(_str) \
67 BT_APPEND_CAUSE_STR_AND_RETHROW_EX((BT_CLOG_CFG), _str)
68
69/*
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`.
73 */
74#define BT_APPEND_CAUSE_ERRNO_AND_THROW_EX(_log_cfg, _exc_cls, _init_msg, _fmt, ...) \
75 do { \
76 BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
77 throw _exc_cls {}; \
78 } while (false)
79
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__)
82
83/*
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.
87 */
88#define BT_APPEND_CAUSE_ERRNO_AND_RETHROW_EX(_log_cfg, _init_msg, _fmt, ...) \
89 do { \
90 BT_APPEND_CAUSE_ERRNO_EX((_log_cfg), _init_msg, _fmt, ##__VA_ARGS__); \
91 throw; \
92 } while (false)
93
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__)
96
97#endif /* BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_THROW_HPP */
This page took 0.031427 seconds and 4 git commands to generate.