1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 3<title>std::error_code error_from_exception(std::exception_ptr &&ep = std::current_exception(), std::error_code not_matched = std::make_error_code(std::errc::resource_unavailable_try_again)) noexcept - Boost.Outcome documentation</title> 4<link rel="stylesheet" href="../../css/boost.css" type="text/css"> 5<meta name="generator" content="Hugo 0.52 with Boostdoc theme"> 6<meta name="viewport" content="width=device-width,initial-scale=1.0"/> 7 8<link rel="icon" href="../../images/favicon.ico" type="image/ico"/> 9<body><div class="spirit-nav"> 10<a accesskey="p" href="../../reference/functions/try_operation_return_as.html"><img src="../../images/prev.png" alt="Prev"></a> 11 <a accesskey="u" href="../../reference/functions.html"><img src="../../images/up.png" alt="Up"></a> 12 <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference/functions/strong_swap.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content"> 13 <div class="titlepage"><div><div><h1 style="clear: both"><code>std::error_code error_from_exception(std::exception_ptr &&ep = std::current_exception(), std::error_code not_matched = std::make_error_code(std::errc::resource_unavailable_try_again)) noexcept</code></h1></div></div></div> 14 <p>This function saves writing boilerplate by rethrowing <code>ep</code> within a <code>try</code> 15block, with a long sequence of <code>catch()</code> handlers, one for every standard 16C++ exception type which has a near or exact equivalent code in 17<a href="https://en.cppreference.com/w/cpp/error/errc" class="api-reference" target="_blank"><i class="fa fa-book" aria-hidden="true"></i> <code>std::errc</code></a> 18.</p> 19 20<p>If matched, <code>ep</code> is set to a default constructed 21<a href="https://en.cppreference.com/w/cpp/error/exception_ptr" class="api-reference" target="_blank"><i class="fa fa-book" aria-hidden="true"></i> <code>std::exception_ptr</code></a> 22, 23and a 24<a href="https://en.cppreference.com/w/cpp/error/error_code" class="api-reference" target="_blank"><i class="fa fa-book" aria-hidden="true"></i> <code>std::error_code</code></a> 25 is constructed using the ADL discovered free 26function <code>make_error_code()</code> upon the <code>std::errc</code> enumeration value matching the 27thrown exception.</p> 28 29<p>If not matched, <code>ep</code> is left intact, and the <code>not_matched</code> error code supplied 30is returned instead.</p> 31 32<p><em>Overridable</em>: Not overridable.</p> 33 34<p><em>Requires</em>: C++ exceptions to be globally enabled.</p> 35 36<p><em>Namespace</em>: <code>BOOST_OUTCOME_V2_NAMESPACE</code></p> 37 38<p><em>Header</em>: <code><boost/outcome/utils.hpp></code></p> 39 40 41 </div><p><small>Last revised: February 01, 2019 at 23:42:52 UTC</small></p> 42<hr> 43<div class="spirit-nav"> 44<a accesskey="p" href="../../reference/functions/try_operation_return_as.html"><img src="../../images/prev.png" alt="Prev"></a> 45 <a accesskey="u" href="../../reference/functions.html"><img src="../../images/up.png" alt="Up"></a> 46 <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference/functions/strong_swap.html"><img src="../../images/next.png" alt="Next"></a></div></body> 47</html> 48