ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
try_result.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "../result.hpp"
4
5#include <exception>
6#include <new>
7#include <system_error>
8#include <utility>
9
11{
12
13[[nodiscard]] inline auto
14current_exception_error_code() noexcept -> std::error_code
15{
16 try
17 {
18 throw;
19 }
20 catch (std::system_error const& error)
21 {
22 return error.code();
23 }
24 catch (std::bad_alloc const&)
25 {
26 return std::make_error_code(std::errc::not_enough_memory);
27 }
28 catch (...)
29 {
30 return std::make_error_code(std::errc::state_not_recoverable);
31 }
32}
33
34template <typename Function>
35[[nodiscard]] auto
36try_result(Function&& function) -> decltype(std::forward<Function>(function)())
37{
38 try
39 {
40 return std::forward<Function>(function)();
41 }
42 catch (...)
43 {
45 }
46}
47
48} // namespace threadschedule::detail
Aggregates multiple thread_registry_backend instances into a single queryable view.
auto current_exception_error_code() noexcept -> std::error_code
auto try_result(Function &&function) -> decltype(std::forward< Function >(function)())