Files
hustoj/web/cppreference-zh/chmhelp/cpp-error-error_code-error_code.html
2025-08-01 12:57:54 +08:00

111 lines
7.0 KiB
HTML

<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>std::error_code::error_code</title>
<link rel="stylesheet" href="ext.css" />
<link rel="stylesheet" href="site_modules.css" />
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_error_error_code_error_code skin-cppreference2 action-view cpp-navbar">
<div id="cpp-content-base">
<div id="content"><a id="top"></a>
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::error_code::</span>error_code</h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-error.html">error</a>&lrm; | <a href="cpp-error-error_code.html">error code</a></span></div>
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
<table class="t-dcl-begin">
<tbody>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp">error_code<span class="br0">(</span><span class="br0">)</span> <span class="kw1">noexcept</span><span class="sy4">;</span></span></div>
</td>
<td>(1)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp">error_code<span class="br0">(</span> <span class="kw4">int</span> ec, <span class="kw4">const</span> error_category<span class="sy3">&amp;</span> ecat <span class="br0">)</span> <span class="kw1">noexcept</span><span class="sy4">;</span></span></div>
</td>
<td>(2)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> ErrorCodeEnum <span class="sy1">&gt;</span><br />
error_code<span class="br0">(</span> ErrorCodeEnum e <span class="br0">)</span> <span class="kw1">noexcept</span><span class="sy4">;</span></span></div>
</td>
<td>(3)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>&#26500;&#36896;&#26032;&#30340; error_code &#12290;</p>
<div class="t-li1"><span class="t-li">1)</span> &#26500;&#36896;&#24102;&#40664;&#35748;&#20540;&#30340; error_code &#12290;&#31561;&#20215;&#20110; <span class="t-c"><span class="mw-geshi cpp source-cpp">error_code<span class="br0">(</span><span class="nu0">0</span>, <a href="cpp-error-system_category.html"><span class="kw873">std::<span class="me2">system_category</span></span></a><span class="br0">(</span><span class="br0">)</span><span class="br0">)</span></span></span> &#12290;</div>
<div class="t-li1"><span class="t-li">2)</span> &#20197; <code>ec</code> &#20026;&#24179;&#21488;&#20381;&#36182;&#30340;&#38169;&#35823;&#30721;&#24182;&#20197; <code>ecat</code> &#20026;&#23545;&#24212;&#30340;<a href="cpp-error-error_category.html">&#38169;&#35823;&#31867;&#21035;</a>&#26500;&#36896; error_code &#12290;</div>
<div class="t-li1"><span class="t-li">3)</span> &#20174;&#38169;&#35823;&#30721;&#26522;&#20030; <code>e</code> &#26500;&#36896; error_code &#12290;&#31561;&#20215;&#20110; <span class="t-c"><span class="mw-geshi cpp source-cpp">make_error_code<span class="br0">(</span>e<span class="br0">)</span></span></span> &#65292;&#20854;&#20013; <code>make_error_code</code> &#30001;<a href="cpp-language-adl.html">&#23454;&#21442;&#20381;&#36182;&#26597;&#25214;</a>&#25214;&#21040;&#12290;&#27492;&#37325;&#36733;&#20165;&#33509;<span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="cpp-error-error_code-is_error_code_enum.html"><span class="kw878">std::<span class="me2">is_error_code_enum</span></span></a><span class="sy1">&lt;</span>ErrorCodeEnum<span class="sy1">&gt;</span><span class="sy4">::</span><span class="me2">value</span></span></span> &#20026; <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw2">true</span></span></span> &#25165;&#21442;&#19982;&#37325;&#36733;&#20915;&#35758;&#12290;</div>
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">&#21442;&#25968;</span></h3>
<table class="t-par-begin">
<tr class="t-par">
<td>ec</td>
<td>-</td>
<td>&#29992;&#20197;&#26500;&#36896;&#30340;&#24179;&#21488;&#20381;&#36182;&#30340;&#38169;&#35823;&#30721;</td>
</tr>
<tr class="t-par">
<td>ecat</td>
<td>-</td>
<td>&#23545;&#24212; <code>ec</code> &#30340; error_category</td>
</tr>
<tr class="t-par">
<td>e</td>
<td>-</td>
<td>&#29992;&#20197;&#26500;&#36896;&#30340;&#38169;&#35823;&#30721;&#26522;&#20030;</td>
</tr>
</table>
<h3><span class="mw-headline" id=".E6.B3.A8.E8.A7.A3">&#27880;&#35299;</span></h3>
<p>&#26368;&#21021;&#30340;&#25552;&#26696; <a rel="nofollow" class="external text" href="https://wg21.link/N2422">N2422</a> &#20013;&#26377;&#24847;&#20351;&#29992; ADL &#25152;&#25214;&#21040;&#30340; <code>make_error_code</code> &#65292;&#24182;&#19988;&#24050;&#30693;&#23454;&#29616;&#22343;&#20351;&#29992;&#23427;&#12290;&#28982;&#32780;&#65292;&#26631;&#20934;&#35201;&#27714;&#21482;&#32771;&#34385; <code>std::make_error_code</code> &#37325;&#36733;&#12290;&#27492;&#20026; <a rel="nofollow" class="external text" href="https://cplusplus.github.io/LWG/issue3629">LWG &#38382;&#39064; 3629</a> &#12290;</p>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">&#21442;&#38405;</span></h3>
<table class="t-dsc-begin">
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-error-errc-make_error_code.html"><span class="t-lines"><span>make_error_code<span class="t-dsc-small">(std::errc)</span></span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div>
</td>
<td>&#26500;&#36896; <span class="t-lc"><a href="cpp-error-errc.html">std::errc</a></span> &#38169;&#35823;&#30721;<br />
<span class="t-mark">(&#20989;&#25968;)</span></td>
</tr>
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-io-io_errc-make_error_code.html"><span class="t-lines"><span>make_error_code<span class="t-dsc-small">(std::io_errc)</span></span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div>
</td>
<td>&#26500;&#36896;&#19968;&#20010; iostream &#38169;&#35823;&#30721;<br />
<span class="t-mark">(&#20989;&#25968;)</span></td>
</tr>
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-thread-future_errc-make_error_code.html"><span class="t-lines"><span>make_error_code<span class="t-dsc-small">(std::future_errc)</span></span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div>
</td>
<td>&#26500;&#36896;&#19968;&#20010; future error_code<br />
<span class="t-mark">(&#20989;&#25968;)</span></td>
</tr>
</table>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>