forked from qdrvm/kagome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutcome_throw.hpp
35 lines (30 loc) · 1.05 KB
/
outcome_throw.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef KAGOME_CORE_COMMON_OUTCOME_THROW_HPP
#define KAGOME_CORE_COMMON_OUTCOME_THROW_HPP
#include <boost/system/system_error.hpp>
#include <boost/throw_exception.hpp>
namespace kagome::common {
/**
* @brief throws outcome::result error as boost exception
* @tparam T enum error type, only outcome::result enums are allowed
* @param t error value
*/
template <typename T, typename = std::enable_if_t<std::is_enum_v<T>>>
void raise(T t) {
std::error_code ec = make_error_code(t);
boost::throw_exception(std::system_error(ec));
}
/**
* @brief throws outcome::result error made of error as boost exception
* @tparam T outcome error type
* @param t outcome error value
*/
template <typename T, typename = std::enable_if_t<!std::is_enum_v<T>>>
void raise(const T &t) {
boost::throw_exception(std::system_error(t.value(), t.category()));
}
} // namespace kagome::common
#endif // KAGOME_CORE_COMMON_OUTCOME_THROW_HPP