{"id":2118,"date":"2025-03-24T08:48:15","date_gmt":"2025-03-23T23:48:15","guid":{"rendered":"https:\/\/dexall.co.jp\/articles\/?p=2118"},"modified":"2025-03-24T08:48:41","modified_gmt":"2025-03-23T23:48:41","slug":"c%e3%81%aethrow%e3%82%92%e5%ae%8c%e5%85%a8%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%ef%bc%81%e5%ae%9f%e8%b7%b5%e3%81%a7%e4%bd%bf%e3%81%88%e3%82%8b%e4%be%8b%e5%a4%96%e5%87%a6%e7%90%86%e3%81%ae%e5%ae%9f","status":"publish","type":"post","link":"https:\/\/dexall.co.jp\/articles\/?p=2118","title":{"rendered":"C++\u306ethrow\u3092\u5b8c\u5168\u30de\u30b9\u30bf\u30fc\uff01\u5b9f\u8df5\u3067\u4f7f\u3048\u308b\u4f8b\u5916\u51e6\u7406\u306e\u5b9f\u88c5\u65b9\u6cd57\u9078"},"content":{"rendered":"\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>116<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>121<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>128<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\" data-dialog-title=\"\u76ee\u6b21\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">C++\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406\u306e\u57fa\u790e\u77e5\u8b58<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">\u4f8b\u5916\u51e6\u7406\u304c\u5fc5\u8981\u306a\u7406\u7531\u3068\u30e1\u30ea\u30c3\u30c8<\/a>      <\/li>      <li>        <a href=\"#i-2\">throw\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-3\">try-catch\u69cb\u6587\u3068\u306e\u95a2\u4fc2\u6027<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-4\">\u5b9f\u8df5\u7684\u306athrow\u306e\u4f7f\u7528\u65b9\u6cd5<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-5\">\u30ab\u30b9\u30bf\u30e0\u4f8b\u5916\u30af\u30e9\u30b9\u306e\u4f5c\u6210\u30c6\u30af\u30cb\u30c3\u30af<\/a>      <\/li>      <li>        <a href=\"#i-6\">\u4f8b\u5916\u306e\u968e\u5c64\u69cb\u9020\u306e\u8a2d\u8a08\u65b9\u6cd5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-7\">\u30b9\u30bf\u30c3\u30af\u5dfb\u304d\u623b\u3057\u306e\u30e1\u30ab\u30cb\u30ba\u30e0<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-8\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u8003\u616e\u3057\u305f\u4f8b\u5916\u51e6\u7406\u306e\u5b9f\u88c5<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-9\">\u4f8b\u5916\u51e6\u7406\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u3068\u305d\u306e\u6700\u5c0f\u5316<\/a>      <\/li>      <li>        <a href=\"#i-10\">noexcept\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u52b9\u679c\u7684\u306a\u4f7f\u7528<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-11\">\u4f8b\u5916\u5b89\u5168\u6027\u306e\u78ba\u4fdd\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-12\">\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-13\">\u30b9\u30ed\u30fc\u3092\u4f7f\u7528\u3059\u3079\u304d\u72b6\u6cc1\u3068\u907f\u3051\u308b\u3079\u304d\u72b6\u6cc1<\/a>      <\/li>      <li>        <a href=\"#i-14\">\u30a8\u30e9\u30fc\u30b3\u30fc\u30c9vsthrow\u306e\u4f7f\u7528<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-15\">\u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306ethrow\u7981\u6b62\u30eb\u30fc\u30eb<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-16\">\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u4f8b\u5916\u51e6\u7406\u5b9f\u88c5\u4f8b<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-17\">\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\u3067\u306e\u4f8b\u5916\u51e6\u7406\u30d1\u30bf\u30fc\u30f3<\/a>      <\/li>      <li>        <a href=\"#i-18\">\u975e\u540c\u671f\u51e6\u7406\u306b\u304a\u3051\u308b\u4f8b\u5916\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-19\">\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u901a\u4fe1\u3067\u306e\u4f8b\u5916\u51e6\u7406\u5b9f\u88c5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-20\">\u4f8b\u5916\u51e6\u7406\u306e\u30c7\u30d0\u30c3\u30b0\u3068\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-21\">\u4e00\u822c\u7684\u306a\u4f8b\u5916\u51e6\u7406\u306e\u554f\u984c\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5<\/a>      <\/li>      <li>        <a href=\"#i-22\">\u52b9\u679c\u7684\u306a\u30ed\u30b0\u8a18\u9332\u306e\u5b9f\u88c5\u65b9\u6cd5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-23\">\u30c7\u30d0\u30c3\u30ac\u30fc\u3092\u4f7f\u7528\u3057\u305f\u4f8b\u5916\u306e\u8ffd\u8de1\u30c6\u30af\u30cb\u30c3\u30af<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-24\">\u30c1\u30fc\u30e0\u958b\u767a\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406\u306e\u6a19\u6e96\u5316<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-25\">\u4f8b\u5916\u51e6\u7406\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u306e\u9032\u3081\u65b9<\/a>      <\/li>      <li>        <a href=\"#i-26\">\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3067\u306e\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-27\">\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u5316\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      <a href=\"#\" class=\"sgb-toc-button js-toc-button\" rel=\"nofollow\" data-open-dialog=\"true\"><i class=\"fa fa-list\"><\/i><span class=\"sgb-toc-button__text\">\u76ee\u6b21\u3078<\/span><\/a>\n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">C++\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406\u306e\u57fa\u790e\u77e5\u8b58<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">\u4f8b\u5916\u51e6\u7406\u304c\u5fc5\u8981\u306a\u7406\u7531\u3068\u30e1\u30ea\u30c3\u30c8<\/h3>\n\n\n\n<p>\u4f8b\u5916\u51e6\u7406\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u4e2d\u306b\u767a\u751f\u3059\u308b\u4e88\u671f\u3057\u306a\u3044\u72b6\u6cc1\u3084\u30a8\u30e9\u30fc\u3092\u9069\u5207\u306b\u51e6\u7406\u3059\u308b\u305f\u3081\u306e\u91cd\u8981\u306a\u30e1\u30ab\u30cb\u30ba\u30e0\u3067\u3059\u3002C++\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406\u306e\u4e3b\u306a\u30e1\u30ea\u30c3\u30c8\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u5206\u96e2<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u901a\u5e38\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u30ed\u30b8\u30c3\u30af\u3068\u30a8\u30e9\u30fc\u51e6\u7406\u30ed\u30b8\u30c3\u30af\u3092\u5206\u96e2\u3067\u304d\u308b<\/li>\n\n\n\n<li>\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3068\u4fdd\u5b88\u6027\u304c\u5411\u4e0a\u3059\u308b<\/li>\n\n\n\n<li>\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u306b\u96c6\u4e2d\u3067\u304d\u308b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u306e\u4f1d\u64ad<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u95a2\u6570\u547c\u3073\u51fa\u3057\u30b9\u30bf\u30c3\u30af\u3092\u9061\u3063\u3066\u9069\u5207\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u307e\u3067\u30a8\u30e9\u30fc\u3092\u4f1d\u64ad\u3067\u304d\u308b<\/li>\n\n\n\n<li>\u6df1\u3044\u95a2\u6570\u547c\u3073\u51fa\u3057\u306e\u4e2d\u3067\u767a\u751f\u3057\u305f\u30a8\u30e9\u30fc\u3082\u78ba\u5b9f\u306b\u51e6\u7406\u3067\u304d\u308b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\u306e\u78ba\u5b9f\u6027<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAII\u30d1\u30bf\u30fc\u30f3\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u4f8b\u5916\u767a\u751f\u6642\u3067\u3082\u78ba\u5b9f\u306b\u30ea\u30bd\u30fc\u30b9\u3092\u89e3\u653e\u3067\u304d\u308b<\/li>\n\n\n\n<li>\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u308b<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">throw\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h3>\n\n\n\n<p>throw\u30ad\u30fc\u30ef\u30fc\u30c9\u306f\u3001\u4f8b\u5916\u3092\u6295\u3052\u308b\uff08\u767a\u751f\u3055\u305b\u308b\uff09\u305f\u3081\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u57fa\u672c\u7684\u306a\u4f8b\u5916\u306e\u30b9\u30ed\u30fc\nvoid validateAge(int age) {\n    if (age &lt; 0) {\n        throw std::invalid_argument(\"\u5e74\u9f62\u306f0\u4ee5\u4e0a\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\");\n    }\n    if (age &gt; 150) {\n        throw std::out_of_range(\"\u5e74\u9f62\u304c\u7bc4\u56f2\u5916\u3067\u3059\");\n    }\n    \/\/ \u6b63\u5e38\u306a\u51e6\u7406\u3092\u7d9a\u884c\n}\n\n\/\/ \u4efb\u610f\u306e\u578b\u306e\u30b9\u30ed\u30fc\nclass DatabaseError {\npublic:\n    DatabaseError(const std::string&amp; message) : message_(message) {}\n    std::string what() const { return message_; }\nprivate:\n    std::string message_;\n};\n\nvoid connectToDatabase() {\n    if (\/* \u63a5\u7d9a\u5931\u6557 *\/) {\n        throw DatabaseError(\"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-3\">try-catch\u69cb\u6587\u3068\u306e\u95a2\u4fc2\u6027<\/h3>\n\n\n\n<p>try-catch\u69cb\u6587\u306f\u3001\u6295\u3052\u3089\u308c\u305f\u4f8b\u5916\u3092\u6355\u6349\u3057\u3066\u51e6\u7406\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u5305\u62ec\u7684\u306a\u4f8b\u3067\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;iostream&gt;\n#include &lt;stdexcept&gt;\n#include &lt;memory&gt;\n\nclass Resource {\npublic:\n    Resource() { std::cout &lt;&lt; \"\u30ea\u30bd\u30fc\u30b9\u3092\u78ba\u4fdd\u3057\u307e\u3057\u305f\\n\"; }\n    ~Resource() { std::cout &lt;&lt; \"\u30ea\u30bd\u30fc\u30b9\u3092\u89e3\u653e\u3057\u307e\u3057\u305f\\n\"; }\n};\n\nvoid processData() {\n    \/\/ RAII\u306b\u3088\u308b\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\n    std::unique_ptr&lt;Resource&gt; resource = std::make_unique&lt;Resource&gt;();\n\n    \/\/ \u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u51e6\u7406\n    throw std::runtime_error(\"\u30c7\u30fc\u30bf\u51e6\u7406\u4e2d\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\");\n\n    \/\/ \u3053\u306e\u884c\u306f\u5b9f\u884c\u3055\u308c\u306a\u3044\n    std::cout &lt;&lt; \"\u51e6\u7406\u5b8c\u4e86\\n\";\n}\n\nint main() {\n    try {\n        std::cout &lt;&lt; \"\u51e6\u7406\u3092\u958b\u59cb\u3057\u307e\u3059\\n\";\n        processData();\n    }\n    catch (const std::runtime_error&amp; e) {\n        \/\/ runtime_error\u578b\u306e\u4f8b\u5916\u3092\u6355\u6349\n        std::cerr &lt;&lt; \"\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f: \" &lt;&lt; e.what() &lt;&lt; \"\\n\";\n    }\n    catch (const std::exception&amp; e) {\n        \/\/ \u305d\u306e\u4ed6\u306e\u6a19\u6e96\u4f8b\u5916\u3092\u6355\u6349\n        std::cerr &lt;&lt; \"\u4e88\u671f\u3057\u306a\u3044\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f: \" &lt;&lt; e.what() &lt;&lt; \"\\n\";\n    }\n    catch (...) {\n        \/\/ \u305d\u306e\u4ed6\u5168\u3066\u306e\u4f8b\u5916\u3092\u6355\u6349\n        std::cerr &lt;&lt; \"\u4e0d\u660e\u306a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\\n\";\n    }\n\n    std::cout &lt;&lt; \"\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d42\u4e86\u3057\u307e\u3059\\n\";\n    return 0;\n}<\/pre>\n\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306e\u5b9f\u884c\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u51e6\u7406\u3092\u958b\u59cb\u3057\u307e\u3059\n\u30ea\u30bd\u30fc\u30b9\u3092\u78ba\u4fdd\u3057\u307e\u3057\u305f\n\u30ea\u30bd\u30fc\u30b9\u3092\u89e3\u653e\u3057\u307e\u3057\u305f\n\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f: \u30c7\u30fc\u30bf\u51e6\u7406\u4e2d\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\n\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d42\u4e86\u3057\u307e\u3059<\/pre>\n\n\n\n<p>\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f8b\u5916\u51e6\u7406\u306e\u968e\u5c64\u69cb\u9020<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u3088\u308a\u5177\u4f53\u7684\u306a\u4f8b\u5916\u304b\u3089\u9806\u306b\u6355\u6349\u3059\u308b<\/li>\n\n\n\n<li>\u57fa\u5e95\u30af\u30e9\u30b9\u306e\u4f8b\u5916\u306f\u5f8c\u308d\u306b\u914d\u7f6e\u3059\u308b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAII\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3001\u4f8b\u5916\u767a\u751f\u6642\u3067\u3082\u30ea\u30bd\u30fc\u30b9\u304c\u78ba\u5b9f\u306b\u89e3\u653e\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b<\/li>\n\n\n\n<li>\u30b9\u30de\u30fc\u30c8\u30dd\u30a4\u30f3\u30bf\u3092\u6d3b\u7528\u3059\u308b<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f8b\u5916\u306e\u518d\u30b9\u30ed\u30fc<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>catch\u6587\u5185\u3067<code>throw;<\/code>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u6355\u6349\u3057\u305f\u4f8b\u5916\u3092\u518d\u30b9\u30ed\u30fc\u3067\u304d\u308b<\/li>\n\n\n\n<li>\u4f8b\u5916\u306e\u51e6\u7406\u3092\u4e0a\u4f4d\u306e\u5c64\u306b\u59d4\u306d\u308b\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u306e\u57fa\u790e\u77e5\u8b58\u3092\u8e0f\u307e\u3048\u3066\u3001\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3088\u308a\u5b9f\u8df5\u7684\u306athrow\u306e\u4f7f\u7528\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-4\">\u5b9f\u8df5\u7684\u306athrow\u306e\u4f7f\u7528\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-5\">\u30ab\u30b9\u30bf\u30e0\u4f8b\u5916\u30af\u30e9\u30b9\u306e\u4f5c\u6210\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n\n\n\n<p>\u30ab\u30b9\u30bf\u30e0\u4f8b\u5916\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u56fa\u6709\u306e\u30a8\u30e9\u30fc\u72b6\u614b\u3092\u9069\u5207\u306b\u8868\u73fe\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u3001\u52b9\u679c\u7684\u306a\u30ab\u30b9\u30bf\u30e0\u4f8b\u5916\u30af\u30e9\u30b9\u306e\u5b9f\u88c5\u4f8b\u3067\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdexcept&gt;\n#include &lt;string&gt;\n#include &lt;sstream&gt;\n\n\/\/ \u57fa\u5e95\u3068\u306a\u308b\u4f8b\u5916\u30af\u30e9\u30b9\nclass ApplicationError : public std::runtime_error {\npublic:\n    ApplicationError(const std::string&amp; message, const char* file, int line)\n        : std::runtime_error(formatMessage(message, file, line))\n        , message_(message)\n        , file_(file)\n        , line_(line) {}\n\n    \/\/ \u30a8\u30e9\u30fc\u60c5\u5831\u3078\u306e\u30a2\u30af\u30bb\u30b5\n    const std::string&amp; getMessage() const { return message_; }\n    const std::string&amp; getFile() const { return file_; }\n    int getLine() const { return line_; }\n\nprivate:\n    static std::string formatMessage(const std::string&amp; message, const char* file, int line) {\n        std::ostringstream oss;\n        oss &lt;&lt; \"Error at \" &lt;&lt; file &lt;&lt; \":\" &lt;&lt; line &lt;&lt; \" - \" &lt;&lt; message;\n        return oss.str();\n    }\n\n    std::string message_;\n    std::string file_;\n    int line_;\n};\n\n\/\/ \u5177\u4f53\u7684\u306a\u4f8b\u5916\u30af\u30e9\u30b9\nclass DatabaseError : public ApplicationError {\npublic:\n    DatabaseError(const std::string&amp; message, const char* file, int line)\n        : ApplicationError(\"Database: \" + message, file, line) {}\n};\n\nclass ValidationError : public ApplicationError {\npublic:\n    ValidationError(const std::string&amp; message, const char* file, int line)\n        : ApplicationError(\"Validation: \" + message, file, line) {}\n};\n\n\/\/ \u30de\u30af\u30ed\u3092\u4f7f\u7528\u3057\u3066\u547c\u3073\u51fa\u3057\u5143\u306e\u60c5\u5831\u3092\u81ea\u52d5\u7684\u306b\u53d6\u5f97\n#define THROW_DB_ERROR(message) throw DatabaseError(message, __FILE__, __LINE__)\n#define THROW_VALIDATION_ERROR(message) throw ValidationError(message, __FILE__, __LINE__)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-6\">\u4f8b\u5916\u306e\u968e\u5c64\u69cb\u9020\u306e\u8a2d\u8a08\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u52b9\u679c\u7684\u306a\u4f8b\u5916\u968e\u5c64\u3092\u8a2d\u8a08\u3059\u308b\u3053\u3068\u3067\u3001\u30a8\u30e9\u30fc\u306e\u7a2e\u985e\u3092\u9069\u5207\u306b\u5206\u985e\u3057\u3001\u51e6\u7406\u3092\u7c21\u6f54\u306b\u8a18\u8ff0\u3067\u304d\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u696d\u52d9\u30c9\u30e1\u30a4\u30f3\u56fa\u6709\u306e\u4f8b\u5916\u968e\u5c64\u306e\u4f8b\nclass DomainError : public ApplicationError {\npublic:\n    using ApplicationError::ApplicationError;\n};\n\nclass OrderError : public DomainError {\npublic:\n    OrderError(const std::string&amp; message, const char* file, int line)\n        : DomainError(\"Order: \" + message, file, line) {}\n};\n\nclass PaymentError : public DomainError {\npublic:\n    PaymentError(const std::string&amp; message, const char* file, int line)\n        : DomainError(\"Payment: \" + message, file, line) {}\n};\n\n\/\/ \u4f7f\u7528\u4f8b\nvoid processOrder(const Order&amp; order) {\n    try {\n        validateOrder(order);\n        processPayment(order);\n        updateInventory(order);\n    }\n    catch (const PaymentError&amp; e) {\n        \/\/ \u652f\u6255\u3044\u95a2\u9023\u306e\u30a8\u30e9\u30fc\u51e6\u7406\n        notifyCustomerAboutPaymentIssue(order, e.getMessage());\n        throw; \/\/ \u4e0a\u4f4d\u5c64\u3078\u306e\u518d\u30b9\u30ed\u30fc\n    }\n    catch (const OrderError&amp; e) {\n        \/\/ \u6ce8\u6587\u95a2\u9023\u306e\u30a8\u30e9\u30fc\u51e6\u7406\n        logOrderError(order, e);\n        throw;\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-7\">\u30b9\u30bf\u30c3\u30af\u5dfb\u304d\u623b\u3057\u306e\u30e1\u30ab\u30cb\u30ba\u30e0<\/h3>\n\n\n\n<p>\u4f8b\u5916\u304c\u6295\u3052\u3089\u308c\u308b\u3068\u3001\u30b9\u30bf\u30c3\u30af\u306e\u5dfb\u304d\u623b\u3057\uff08\u30b9\u30bf\u30c3\u30af\u30a2\u30f3\u30ef\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\uff09\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u3053\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306b\u6d3b\u7528\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;memory&gt;\n#include &lt;vector&gt;\n\nclass Resource {\npublic:\n    Resource(const std::string&amp; name) : name_(name) {\n        std::cout &lt;&lt; \"Resource \" &lt;&lt; name_ &lt;&lt; \" acquired\\n\";\n    }\n    ~Resource() {\n        std::cout &lt;&lt; \"Resource \" &lt;&lt; name_ &lt;&lt; \" released\\n\";\n    }\nprivate:\n    std::string name_;\n};\n\nclass ResourceManager {\npublic:\n    void operateWithResources() {\n        \/\/ \u30b9\u30de\u30fc\u30c8\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u7528\u3057\u305f\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\n        auto resource1 = std::make_unique&lt;Resource&gt;(\"DB Connection\");\n\n        try {\n            \/\/ \u8907\u6570\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u78ba\u4fdd\n            std::vector&lt;std::unique_ptr&lt;Resource&gt;&gt; resources;\n            resources.push_back(std::make_unique&lt;Resource&gt;(\"File Handle\"));\n            resources.push_back(std::make_unique&lt;Resource&gt;(\"Network Socket\"));\n\n            \/\/ \u4f8b\u5916\u3092\u6295\u3052\u308b\u51e6\u7406\n            throw std::runtime_error(\"Operation failed\");\n\n        } catch (const std::exception&amp; e) {\n            std::cerr &lt;&lt; \"Error: \" &lt;&lt; e.what() &lt;&lt; \"\\n\";\n            \/\/ \u30ea\u30bd\u30fc\u30b9\u306f\u81ea\u52d5\u7684\u306b\u89e3\u653e\u3055\u308c\u308b\n        }\n        \/\/ resource1\u3082\u81ea\u52d5\u7684\u306b\u89e3\u653e\u3055\u308c\u308b\n    }\n};<\/pre>\n\n\n\n<p>\u5b9f\u884c\u7d50\u679c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Resource DB Connection acquired\nResource File Handle acquired\nResource Network Socket acquired\nError: Operation failed\nResource Network Socket released\nResource File Handle released\nResource DB Connection released<\/pre>\n\n\n\n<p>\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f8b\u5916\u968e\u5c64\u306e\u8a2d\u8a08<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5177\u4f53\u7684\u306a\u30a8\u30e9\u30fc\u30bf\u30a4\u30d7\u3054\u3068\u306b\u5c02\u7528\u306e\u4f8b\u5916\u30af\u30e9\u30b9\u3092\u4f5c\u6210<\/li>\n\n\n\n<li>\u5171\u901a\u306e\u6a5f\u80fd\u306f\u57fa\u5e95\u30af\u30e9\u30b9\u306b\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30de\u30af\u30ed\u3092\u4f7f\u7528\u3057\u3066\u547c\u3073\u51fa\u3057\u60c5\u5831\u3092\u81ea\u52d5\u7684\u306b\u53d6\u5f97<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAII\u30d1\u30bf\u30fc\u30f3\u3092\u4e00\u8cab\u3057\u3066\u4f7f\u7528<\/li>\n\n\n\n<li>\u30b9\u30de\u30fc\u30c8\u30dd\u30a4\u30f3\u30bf\u3092\u6d3b\u7528<\/li>\n\n\n\n<li>\u4f8b\u5916\u5b89\u5168\u6027\u3092\u78ba\u4fdd<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u60c5\u5831\u306e\u63d0\u4f9b<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u52a0\u3048\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u884c\u756a\u53f7\u3082\u542b\u3081\u308b<\/li>\n\n\n\n<li>\u30c7\u30d0\u30c3\u30b0\u306b\u5f79\u7acb\u3064\u60c5\u5831\u3092\u9069\u5207\u306b\u63d0\u4f9b<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b9f\u8df5\u7684\u306a\u30c6\u30af\u30cb\u30c3\u30af\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u5805\u7262\u3067\u4fdd\u5b88\u6027\u306e\u9ad8\u3044\u4f8b\u5916\u51e6\u7406\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-8\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u8003\u616e\u3057\u305f\u4f8b\u5916\u51e6\u7406\u306e\u5b9f\u88c5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-9\">\u4f8b\u5916\u51e6\u7406\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u3068\u305d\u306e\u6700\u5c0f\u5316<\/h3>\n\n\n\n<p>\u4f8b\u5916\u51e6\u7406\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u304c\u5b58\u5728\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b9\u30bf\u30c3\u30af\u5dfb\u304d\u623b\u3057\u306e\u30b3\u30b9\u30c8<\/li>\n\n\n\n<li>\u4f8b\u5916\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u751f\u6210\u3068\u7834\u68c4\u306e\u30b3\u30b9\u30c8<\/li>\n\n\n\n<li>try-catch\u30d6\u30ed\u30c3\u30af\u306b\u3088\u308b\u6700\u9069\u5316\u306e\u5236\u9650<\/li>\n<\/ol>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u3092\u6700\u5c0f\u5316\u3059\u308b\u305f\u3081\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;chrono&gt;\n#include &lt;iostream&gt;\n#include &lt;stdexcept&gt;\n\n\/\/ \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u8a08\u6e2c\u7528\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30af\u30e9\u30b9\nclass Timer {\n    std::chrono::high_resolution_clock::time_point start_;\npublic:\n    Timer() : start_(std::chrono::high_resolution_clock::now()) {}\n    ~Timer() {\n        auto end = std::chrono::high_resolution_clock::now();\n        auto duration = std::chrono::duration_cast&lt;std::chrono::microseconds&gt;(end - start_);\n        std::cout &lt;&lt; \"\u5b9f\u884c\u6642\u9593: \" &lt;&lt; duration.count() &lt;&lt; \"\u03bcs\\n\";\n    }\n};\n\n\/\/ \u6700\u9069\u5316\u4f8b1: \u4f8b\u5916\u3092\u6295\u3052\u308b\u983b\u5ea6\u3092\u524a\u6e1b\nclass OptimizedValidator {\npublic:\n    bool validateValue(int value, std::string&amp; error) {\n        if (value &lt; 0) {\n            error = \"\u5024\u304c\u8ca0\u6570\u3067\u3059\";\n            return false;\n        }\n        if (value &gt; 100) {\n            error = \"\u5024\u304c\u7bc4\u56f2\u5916\u3067\u3059\";\n            return false;\n        }\n        return true;\n    }\n};\n\n\/\/ \u6bd4\u8f03\u7528\uff1a\u4f8b\u5916\u3092\u4f7f\u7528\u3059\u308b\u5b9f\u88c5\nclass ExceptionBasedValidator {\npublic:\n    void validateValue(int value) {\n        if (value &lt; 0) {\n            throw std::invalid_argument(\"\u5024\u304c\u8ca0\u6570\u3067\u3059\");\n        }\n        if (value &gt; 100) {\n            throw std::out_of_range(\"\u5024\u304c\u7bc4\u56f2\u5916\u3067\u3059\");\n        }\n    }\n};\n\n\/\/ \u30d9\u30f3\u30c1\u30de\u30fc\u30af\u95a2\u6570\nvoid runBenchmark() {\n    const int ITERATIONS = 1000000;\n\n    \/\/ \u30a8\u30e9\u30fc\u30b1\u30fc\u30b9\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\n    {\n        Timer t;\n        OptimizedValidator validator;\n        std::string error;\n        for (int i = 0; i &lt; ITERATIONS; ++i) {\n            if (!validator.validateValue(-1, error)) {\n                \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\n            }\n        }\n    }\n\n    {\n        Timer t;\n        ExceptionBasedValidator validator;\n        for (int i = 0; i &lt; ITERATIONS; ++i) {\n            try {\n                validator.validateValue(-1);\n            } catch (const std::exception&amp;) {\n                \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\n            }\n        }\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-10\">noexcept\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u52b9\u679c\u7684\u306a\u4f7f\u7528<\/h3>\n\n\n\n<p><code>noexcept<\/code>\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u9069\u5207\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30b3\u30f3\u30d1\u30a4\u30e9\u306e\u6700\u9069\u5316\u3092\u4fc3\u9032\u3067\u304d\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class ResourceManager {\npublic:\n    \/\/ \u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u306f\u6697\u9ed9\u7684\u306bnoexcept\n    ~ResourceManager() {\n        cleanup();\n    }\n\n    \/\/ \u4f8b\u5916\u3092\u6295\u3052\u306a\u3044\u64cd\u4f5c\u306b\u306fnoexcept\u3092\u6307\u5b9a\n    void cleanup() noexcept {\n        try {\n            \/\/ \u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u51e6\u7406\n        } catch (...) {\n            \/\/ \u5168\u3066\u306e\u4f8b\u5916\u3092\u5185\u90e8\u3067\u51e6\u7406\n        }\n    }\n\n    \/\/ move\u64cd\u4f5c\u306f\u3067\u304d\u308b\u3060\u3051noexcept\u306b\u3059\u308b\n    ResourceManager(ResourceManager&amp;&amp; other) noexcept\n        : resource_(std::exchange(other.resource_, nullptr)) {}\n\n    ResourceManager&amp; operator=(ResourceManager&amp;&amp; other) noexcept {\n        if (this != &amp;other) {\n            cleanup();\n            resource_ = std::exchange(other.resource_, nullptr);\n        }\n        return *this;\n    }\n\nprivate:\n    void* resource_ = nullptr;\n};<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-11\">\u4f8b\u5916\u5b89\u5168\u6027\u306e\u78ba\u4fdd\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u5f37\u3044\u4f8b\u5916\u4fdd\u8a3c\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306e\u30c6\u30af\u30cb\u30c3\u30af\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;vector&gt;\n#include &lt;memory&gt;\n\nclass Transaction {\npublic:\n    \/\/ \u30b3\u30d4\u30fc\u64cd\u4f5c\u3092\u7121\u52b9\u5316\n    Transaction(const Transaction&amp;) = delete;\n    Transaction&amp; operator=(const Transaction&amp;) = delete;\n\n    \/\/ \u5f37\u3044\u4f8b\u5916\u4fdd\u8a3c\u3092\u63d0\u4f9b\u3059\u308b\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u51e6\u7406\n    template&lt;typename Func&gt;\n    static void execute(Func&amp;&amp; operation) {\n        Transaction tx;  \/\/ RAII\u306b\u3088\u308b\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u4fdd\u8a3c\n        operation();     \/\/ \u64cd\u4f5c\u306e\u5b9f\u884c\n        tx.commit();     \/\/ \u6210\u529f\u6642\u306e\u30b3\u30df\u30c3\u30c8\n    }\n\nprivate:\n    Transaction() = default;\n\n    void commit() {\n        committed_ = true;\n    }\n\n    ~Transaction() {\n        if (!committed_) {\n            \/\/ \u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u51e6\u7406\n        }\n    }\n\n    bool committed_ = false;\n};\n\n\/\/ \u4f7f\u7528\u4f8b\uff1a\u5f37\u3044\u4f8b\u5916\u4fdd\u8a3c\u3092\u6301\u3064\u30d9\u30af\u30bf\u64cd\u4f5c\ntemplate&lt;typename T&gt;\nvoid safeVectorOperation(std::vector&lt;T&gt;&amp; vec, const T&amp; newElement) {\n    \/\/ \u4e00\u6642\u30b3\u30d4\u30fc\u3092\u4f5c\u6210\n    auto tempVec = vec;\n\n    \/\/ \u64cd\u4f5c\u3092\u5b9f\u884c\uff08\u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u3042\u308a\uff09\n    tempVec.push_back(newElement);\n\n    \/\/ \u6210\u529f\u3057\u305f\u5834\u5408\u306e\u307f\u3001\u5143\u306e\u30d9\u30af\u30bf\u3092\u66f4\u65b0\n    vec.swap(tempVec);\n}<\/pre>\n\n\n\n<p>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316\u306e\u305f\u3081\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f8b\u5916\u306e\u4f7f\u7528\u983b\u5ea6<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u901a\u5e38\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u306b\u306f\u4f7f\u7528\u3057\u306a\u3044<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u72b6\u614b\u306e\u8fd4\u5374\u306b\u306fbool\/status\u3092\u4f7f\u7528<\/li>\n\n\n\n<li>\u672c\u5f53\u306b\u7570\u5e38\u306a\u72b6\u6cc1\u3067\u306e\u307f\u4f8b\u5916\u3092\u4f7f\u7528<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f8b\u5916\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u8a2d\u8a08<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c0f\u3055\u304f\u3001\u8efd\u91cf\u306a\u4f8b\u5916\u30af\u30e9\u30b9\u3092\u8a2d\u8a08<\/li>\n\n\n\n<li>\u4eee\u60f3\u95a2\u6570\u306e\u4f7f\u7528\u3092\u6700\u5c0f\u9650\u306b<\/li>\n\n\n\n<li>\u30e1\u30c3\u30bb\u30fc\u30b8\u6587\u5b57\u5217\u306f\u5fc5\u8981\u306a\u5834\u5408\u306e\u307f\u4fdd\u6301<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b3\u30f3\u30d1\u30a4\u30e9\u6700\u9069\u5316\u306e\u6d3b\u7528<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>noexcept\u3092\u9069\u5207\u306b\u4f7f\u7528<\/li>\n\n\n\n<li>move\u64cd\u4f5c\u3092noexcept\u306b\u3059\u308b<\/li>\n\n\n\n<li>\u4f8b\u5916\u4ed5\u69d8\u3092\u660e\u78ba\u306b\u5b9a\u7fa9<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u9069\u5207\u306b\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u4f8b\u5916\u51e6\u7406\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u3092\u6700\u5c0f\u9650\u306b\u6291\u3048\u3064\u3064\u3001\u5805\u7262\u306a\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-12\">\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-13\">\u30b9\u30ed\u30fc\u3092\u4f7f\u7528\u3059\u3079\u304d\u72b6\u6cc1\u3068\u907f\u3051\u308b\u3079\u304d\u72b6\u6cc1<\/h3>\n\n\n\n<p>\u4f8b\u5916\u51e6\u7406\u306e\u9069\u5207\u306a\u4f7f\u7528\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u306f\u3001\u5805\u7262\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3059\u308b\u4e0a\u3067\u91cd\u8981\u3067\u3059\u3002\u4ee5\u4e0b\u306b\u3001throw\u3092\u4f7f\u7528\u3059\u3079\u304d\u72b6\u6cc1\u3068\u907f\u3051\u308b\u3079\u304d\u72b6\u6cc1\u3092\u793a\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class FileManager {\npublic:\n    \/\/ \u826f\u3044\u4f8b\uff1a\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306e\u81f4\u547d\u7684\u306a\u30a8\u30e9\u30fc\n    FileManager(const std::string&amp; path) {\n        file_ = std::fopen(path.c_str(), \"r\");\n        if (!file_) {\n            throw std::runtime_error(\"\u30d5\u30a1\u30a4\u30eb\u3092\u30aa\u30fc\u30d7\u30f3\u3067\u304d\u307e\u305b\u3093: \" + path);\n        }\n    }\n\n    \/\/ \u826f\u3044\u4f8b\uff1a\u56de\u5fa9\u4e0d\u53ef\u80fd\u306a\u30a8\u30e9\u30fc\n    void writeData(const std::vector&lt;char&gt;&amp; data) {\n        if (std::fwrite(data.data(), 1, data.size(), file_) != data.size()) {\n            throw std::runtime_error(\"\u30d5\u30a1\u30a4\u30eb\u66f8\u304d\u8fbc\u307f\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n        }\n    }\n\n    \/\/ \u60aa\u3044\u4f8b\uff1a\u4e88\u671f\u3055\u308c\u308b\u72b6\u6cc1\u3067\u306e\u4f8b\u5916\u4f7f\u7528\n    bool hasNextLine() {\n        if (std::feof(file_)) {\n            throw std::runtime_error(\"\u30d5\u30a1\u30a4\u30eb\u306e\u7d42\u7aef\u306b\u9054\u3057\u307e\u3057\u305f\"); \/\/ \u4e0d\u9069\u5207\n        }\n        return true;\n    }\n\n    \/\/ \u826f\u3044\u4f8b\uff1a\u4e88\u671f\u3055\u308c\u308b\u72b6\u6cc1\u3067\u306e\u623b\u308a\u5024\u4f7f\u7528\n    std::optional&lt;std::string&gt; readNextLine() {\n        std::string line;\n        if (std::fgets(buffer_, sizeof(buffer_), file_)) {\n            line = buffer_;\n            return line;\n        }\n        return std::nullopt;\n    }\n\nprivate:\n    FILE* file_;\n    char buffer_[1024];\n};<\/pre>\n\n\n\n<p>\u30b9\u30ed\u30fc\u3092\u4f7f\u7528\u3059\u3079\u304d\u72b6\u6cc1\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306e\u30ea\u30bd\u30fc\u30b9\u78ba\u4fdd\u5931\u6557<\/li>\n\n\n\n<li>\u56de\u5fa9\u4e0d\u53ef\u80fd\u306a\u30a8\u30e9\u30fc\u72b6\u614b<\/li>\n\n\n\n<li>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u524d\u63d0\u6761\u4ef6\u9055\u53cd<\/li>\n\n\n\n<li>\u30b7\u30b9\u30c6\u30e0\u30ea\u30bd\u30fc\u30b9\u306e\u67af\u6e07<\/li>\n<\/ol>\n\n\n\n<p>\u907f\u3051\u308b\u3079\u304d\u72b6\u6cc1\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u901a\u5e38\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u306e\u4e00\u90e8<\/li>\n\n\n\n<li>\u4e88\u671f\u3055\u308c\u308b\u72b6\u6cc1\uff08\u30d5\u30a1\u30a4\u30eb\u7d42\u7aef\u306a\u3069\uff09<\/li>\n\n\n\n<li>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30af\u30ea\u30c6\u30a3\u30ab\u30eb\u306a\u90e8\u5206<\/li>\n\n\n\n<li>\u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u5185<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-14\">\u30a8\u30e9\u30fc\u30b3\u30fc\u30c9vsthrow\u306e\u4f7f\u7528<\/h3>\n\n\n\n<p>\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u9069\u5207\u306a\u30a8\u30e9\u30fc\u51e6\u7406\u65b9\u6cd5\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class DatabaseConnection {\npublic:\n    \/\/ \u30a8\u30e9\u30fc\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3059\u308b\u4f8b\uff08\u983b\u7e41\u306b\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u30a8\u30e9\u30fc\uff09\n    enum class QueryStatus {\n        Success,\n        ConnectionLost,\n        InvalidQuery,\n        NoResults\n    };\n\n    QueryStatus executeQuery(const std::string&amp; query, QueryResult&amp; result) noexcept {\n        if (!isConnected()) {\n            return QueryStatus::ConnectionLost;\n        }\n        if (!validateQuery(query)) {\n            return QueryStatus::InvalidQuery;\n        }\n        \/\/ \u30af\u30a8\u30ea\u5b9f\u884c...\n        return QueryStatus::Success;\n    }\n\n    \/\/ \u4f8b\u5916\u3092\u4f7f\u7528\u3059\u308b\u4f8b\uff08\u6df1\u523b\u306a\u30a8\u30e9\u30fc\uff09\n    void connect(const std::string&amp; connectionString) {\n        if (!tryConnect(connectionString)) {\n            throw DatabaseError(\"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n        }\n    }\n\n    \/\/ \u623b\u308a\u5024\u3068\u30a8\u30e9\u30fc\u60c5\u5831\u306e\u7d44\u307f\u5408\u308f\u305b\n    struct QueryResponse {\n        bool success;\n        std::string errorMessage;\n        std::vector&lt;Row&gt; results;\n    };\n\n    QueryResponse tryExecuteQuery(const std::string&amp; query) noexcept {\n        try {\n            auto results = executeQueryImpl(query);\n            return {true, \"\", results};\n        } catch (const std::exception&amp; e) {\n            return {false, e.what(), {}};\n        }\n    }\n};<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-15\">\u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306ethrow\u7981\u6b62\u30eb\u30fc\u30eb<\/h3>\n\n\n\n<p>\u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306e\u4f8b\u5916\u51e6\u7406\u306b\u95a2\u3059\u308b\u91cd\u8981\u306a\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class Resource {\npublic:\n    ~Resource() noexcept {  \/\/ \u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u306fnoexcept\u3092\u660e\u793a\u7684\u306b\u6307\u5b9a\n        try {\n            cleanup();\n        } catch (const std::exception&amp; e) {\n            \/\/ \u30a8\u30e9\u30fc\u3092\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u306e\u307f\n            std::cerr &lt;&lt; \"Cleanup failed: \" &lt;&lt; e.what() &lt;&lt; std::endl;\n        } catch (...) {\n            \/\/ \u672a\u77e5\u306e\u4f8b\u5916\u3082\u30ed\u30b0\u306b\u8a18\u9332\n            std::cerr &lt;&lt; \"Unknown error during cleanup\" &lt;&lt; std::endl;\n        }\n    }\n\nprivate:\n    void cleanup() {\n        \/\/ \u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u51e6\u7406\n        if (\/* \u30a8\u30e9\u30fc\u767a\u751f *\/) {\n            throw std::runtime_error(\"\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n        }\n    }\n};\n\n\/\/ RAII\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u305f\u5b89\u5168\u306a\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\nclass SafeResource {\n    std::unique_ptr&lt;Resource&gt; resource_;\npublic:\n    void performOperation() {\n        \/\/ \u4f8b\u5916\u304c\u767a\u751f\u3057\u3066\u3082\u3001\u30ea\u30bd\u30fc\u30b9\u306f\u5b89\u5168\u306b\u89e3\u653e\u3055\u308c\u308b\n        resource_-&gt;doSomething();\n    }\n};<\/pre>\n\n\n\n<p>\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u8a2d\u8a08\u6307\u91dd\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u306e\u7a2e\u985e\u306b\u3088\u308b\u4f7f\u3044\u5206\u3051<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u81f4\u547d\u7684\u30a8\u30e9\u30fc \u2192 \u4f8b\u5916\u3092\u4f7f\u7528<\/li>\n\n\n\n<li>\u4e88\u671f\u3055\u308c\u308b\u30a8\u30e9\u30fc \u2192 \u623b\u308a\u5024\u3092\u4f7f\u7528<\/li>\n\n\n\n<li>\u975e\u540c\u671f\u51e6\u7406\u306e\u30a8\u30e9\u30fc \u2192 \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\/Promise\u3092\u4f7f\u7528<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u60c5\u5831\u306e\u63d0\u4f9b<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u3092\u660e\u78ba\u306b\u793a\u3059<\/li>\n\n\n\n<li>\u56de\u5fa9\u306e\u305f\u3081\u306e\u30d2\u30f3\u30c8\u3092\u542b\u3081\u308b<\/li>\n\n\n\n<li>\u30c7\u30d0\u30c3\u30b0\u306b\u5fc5\u8981\u306a\u60c5\u5831\u3092\u4ed8\u52a0<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\u3068\u306e\u7d71\u5408<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAII\u30d1\u30bf\u30fc\u30f3\u3092\u4e00\u8cab\u3057\u3066\u4f7f\u7528<\/li>\n\n\n\n<li>\u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306f\u4f8b\u5916\u3092\u6295\u3052\u306a\u3044<\/li>\n\n\n\n<li>\u30b9\u30de\u30fc\u30c8\u30dd\u30a4\u30f3\u30bf\u3092\u6d3b\u7528<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u9069\u5207\u306b\u9069\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u304c\u9ad8\u304f\u3001\u4fe1\u983c\u6027\u306e\u3042\u308b\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-16\">\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u4f8b\u5916\u51e6\u7406\u5b9f\u88c5\u4f8b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-17\">\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\u3067\u306e\u4f8b\u5916\u51e6\u7406\u30d1\u30bf\u30fc\u30f3<\/h3>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u3084\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306a\u3069\u3001\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\u3092\u4f34\u3046\u5b9f\u88c5\u3067\u306e\u4f8b\u5916\u51e6\u7406\u30d1\u30bf\u30fc\u30f3\u3092\u7d39\u4ecb\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;memory&gt;\n#include &lt;mutex&gt;\n#include &lt;string&gt;\n\n\/\/ \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u3092\u7ba1\u7406\u3059\u308bRAII\u30af\u30e9\u30b9\nclass DatabaseConnection {\npublic:\n    DatabaseConnection(const std::string&amp; connectionString) {\n        if (!connect(connectionString)) {\n            throw DatabaseError(\"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u306e\u78ba\u7acb\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n        }\n    }\n\n    ~DatabaseConnection() noexcept {\n        try {\n            disconnect();\n        } catch (...) {\n            \/\/ \u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306f\u4f8b\u5916\u3092\u6291\u5236\u3057\u3001\u30ed\u30b0\u306e\u307f\u8a18\u9332\n            std::cerr &lt;&lt; \"\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5207\u65ad\u4e2d\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\\n\";\n        }\n    }\n\n    \/\/ \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u306e\u5b9f\u88c5\u4f8b\n    class ConnectionPool {\n    public:\n        static ConnectionPool&amp; getInstance() {\n            static ConnectionPool instance;\n            return instance;\n        }\n\n        std::shared_ptr&lt;DatabaseConnection&gt; getConnection() {\n            std::lock_guard&lt;std::mutex&gt; lock(mutex_);\n            if (connections_.empty()) {\n                return std::make_shared&lt;DatabaseConnection&gt;(connectionString_);\n            }\n            auto conn = connections_.back();\n            connections_.pop_back();\n            return conn;\n        }\n\n        void returnConnection(std::shared_ptr&lt;DatabaseConnection&gt; conn) {\n            std::lock_guard&lt;std::mutex&gt; lock(mutex_);\n            connections_.push_back(std::move(conn));\n        }\n\n    private:\n        std::vector&lt;std::shared_ptr&lt;DatabaseConnection&gt;&gt; connections_;\n        std::mutex mutex_;\n        std::string connectionString_;\n    };\n\nprivate:\n    bool connect(const std::string&amp; connectionString);\n    void disconnect() noexcept;\n};\n\n\/\/ \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u7ba1\u7406\u306e\u4f8b\nclass Transaction {\npublic:\n    Transaction() {\n        conn_ = ConnectionPool::getInstance().getConnection();\n        if (!beginTransaction()) {\n            throw TransactionError(\"\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u958b\u59cb\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n        }\n    }\n\n    ~Transaction() noexcept {\n        if (!committed_) {\n            try {\n                rollback();\n            } catch (...) {\n                \/\/ \u30ed\u30b0\u8a18\u9332\u306e\u307f\n            }\n        }\n        ConnectionPool::getInstance().returnConnection(conn_);\n    }\n\n    void commit() {\n        if (!commitTransaction()) {\n            throw TransactionError(\"\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u30b3\u30df\u30c3\u30c8\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n        }\n        committed_ = true;\n    }\n\nprivate:\n    std::shared_ptr&lt;DatabaseConnection&gt; conn_;\n    bool committed_ = false;\n    bool beginTransaction();\n    bool commitTransaction();\n    void rollback() noexcept;\n};<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-18\">\u975e\u540c\u671f\u51e6\u7406\u306b\u304a\u3051\u308b\u4f8b\u5916\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/h3>\n\n\n\n<p>\u975e\u540c\u671f\u51e6\u7406\u3067\u306e\u4f8b\u5916\u51e6\u7406\u306e\u5b9f\u88c5\u4f8b\u3092\u793a\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;future&gt;\n#include &lt;thread&gt;\n#include &lt;functional&gt;\n\nclass AsyncOperation {\npublic:\n    \/\/ \u975e\u540c\u671f\u30bf\u30b9\u30af\u306e\u5b9f\u884c\n    template&lt;typename Func&gt;\n    auto executeAsync(Func&amp;&amp; func) -&gt; std::future&lt;decltype(func())&gt; {\n        return std::async(std::launch::async, [func = std::forward&lt;Func&gt;(func)]() {\n            try {\n                return func();\n            } catch (const std::exception&amp; e) {\n                \/\/ \u30a8\u30e9\u30fc\u30ed\u30b0\u306e\u8a18\u9332\n                std::cerr &lt;&lt; \"\u975e\u540c\u671f\u51e6\u7406\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f: \" &lt;&lt; e.what() &lt;&lt; \"\\n\";\n                throw; \/\/ \u547c\u3073\u51fa\u3057\u5143\u306b\u4f8b\u5916\u3092\u4f1d\u64ad\n            }\n        });\n    }\n\n    \/\/ \u4f8b\u5916\u5b89\u5168\u306a\u975e\u540c\u671f\u51e6\u7406\u306e\u5b9f\u88c5\u4f8b\n    class SafeAsyncExecutor {\n    public:\n        template&lt;typename Func&gt;\n        void execute(Func&amp;&amp; func) {\n            auto future = std::async(std::launch::async, [this, func = std::forward&lt;Func&gt;(func)]() {\n                try {\n                    func();\n                } catch (...) {\n                    std::lock_guard&lt;std::mutex&gt; lock(errorMutex_);\n                    error_ = std::current_exception();\n                }\n            });\n            futures_.push_back(std::move(future));\n        }\n\n        \/\/ \u5168\u3066\u306e\u975e\u540c\u671f\u51e6\u7406\u306e\u5b8c\u4e86\u3092\u5f85\u6a5f\n        void waitForCompletion() {\n            for (auto&amp; future : futures_) {\n                future.wait();\n            }\n            \/\/ \u30a8\u30e9\u30fc\u304c\u3042\u308c\u3070\u518d\u30b9\u30ed\u30fc\n            if (error_) {\n                std::rethrow_exception(error_);\n            }\n        }\n\n    private:\n        std::vector&lt;std::future&lt;void&gt;&gt; futures_;\n        std::mutex errorMutex_;\n        std::exception_ptr error_;\n    };\n};<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-19\">\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u901a\u4fe1\u3067\u306e\u4f8b\u5916\u51e6\u7406\u5b9f\u88c5<\/h3>\n\n\n\n<p>\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u901a\u4fe1\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406\u306e\u5b9f\u88c5\u4f8b\u3092\u793a\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;chrono&gt;\n#include &lt;system_error&gt;\n\nclass NetworkClient {\npublic:\n    \/\/ \u30ea\u30c8\u30e9\u30a4\u6a5f\u80fd\u4ed8\u304d\u306e\u901a\u4fe1\u51e6\u7406\n    template&lt;typename Func&gt;\n    auto executeWithRetry(Func&amp;&amp; func, int maxRetries = 3) -&gt; decltype(func()) {\n        int retries = 0;\n        std::chrono::milliseconds delay(100);\n\n        while (true) {\n            try {\n                return func();\n            } catch (const NetworkError&amp; e) {\n                if (++retries &gt; maxRetries) {\n                    throw;\n                }\n                \/\/ \u30a8\u30af\u30b9\u30dd\u30cd\u30f3\u30b7\u30e3\u30eb\u30d0\u30c3\u30af\u30aa\u30d5\n                std::this_thread::sleep_for(delay);\n                delay *= 2;\n                std::cerr &lt;&lt; \"\u901a\u4fe1\u30a8\u30e9\u30fc\u3001\u30ea\u30c8\u30e9\u30a4 \" &lt;&lt; retries &lt;&lt; \"\/\" &lt;&lt; maxRetries \n                         &lt;&lt; \": \" &lt;&lt; e.what() &lt;&lt; \"\\n\";\n            }\n        }\n    }\n\n    \/\/ \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u4ed8\u304d\u306e\u901a\u4fe1\u51e6\u7406\n    template&lt;typename Func&gt;\n    auto executeWithTimeout(Func&amp;&amp; func, \n                          std::chrono::milliseconds timeout) -&gt; decltype(func()) {\n        auto future = std::async(std::launch::async, std::forward&lt;Func&gt;(func));\n\n        if (future.wait_for(timeout) == std::future_status::timeout) {\n            throw TimeoutError(\"\u901a\u4fe1\u51e6\u7406\u304c\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u307e\u3057\u305f\");\n        }\n\n        return future.get(); \/\/ \u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u3001\u3053\u3053\u3067\u518d\u30b9\u30ed\u30fc\u3055\u308c\u308b\n    }\n\n    \/\/ \u5b9f\u969b\u306e\u4f7f\u7528\u4f8b\n    void sendData(const std::vector&lt;uint8_t&gt;&amp; data) {\n        executeWithRetry([&amp;]() {\n            return executeWithTimeout([&amp;]() {\n                return sendDataImpl(data);\n            }, std::chrono::seconds(5));\n        });\n    }\n\nprivate:\n    bool sendDataImpl(const std::vector&lt;uint8_t&gt;&amp; data);\n};<\/pre>\n\n\n\n<p>\u5b9f\u88c5\u6642\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAII\u30d1\u30bf\u30fc\u30f3\u306e\u4e00\u8cab\u3057\u305f\u4f7f\u7528<\/li>\n\n\n\n<li>\u30b9\u30de\u30fc\u30c8\u30dd\u30a4\u30f3\u30bf\u306b\u3088\u308b\u30e1\u30e2\u30ea\u7ba1\u7406<\/li>\n\n\n\n<li>\u9069\u5207\u306a\u30b9\u30b3\u30fc\u30d7\u8a2d\u8a08<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u975e\u540c\u671f\u51e6\u7406<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5916\u306e\u9069\u5207\u306a\u4f1d\u64ad<\/li>\n\n\n\n<li>\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u51e6\u7406\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u72b6\u614b\u306e\u540c\u671f\u7684\u306a\u7ba1\u7406<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u30ea\u30ab\u30d0\u30ea<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30ea\u30c8\u30e9\u30a4\u6a5f\u69cb\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\u51e6\u7406\u306e\u63d0\u4f9b<\/li>\n\n\n\n<li>\u30ed\u30b0\u8a18\u9332\u3068\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b9f\u88c5\u4f8b\u306f\u3001\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u906d\u9047\u3059\u308b\u5178\u578b\u7684\u306a\u30b7\u30ca\u30ea\u30aa\u306b\u5bfe\u5fdc\u3057\u3066\u304a\u308a\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u81ea\u8eab\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u9069\u5fdc\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-20\">\u4f8b\u5916\u51e6\u7406\u306e\u30c7\u30d0\u30c3\u30b0\u3068\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-21\">\u4e00\u822c\u7684\u306a\u4f8b\u5916\u51e6\u7406\u306e\u554f\u984c\u3068\u305d\u306e\u89e3\u6c7a\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u4f8b\u5916\u51e6\u7406\u3067\u983b\u7e41\u306b\u906d\u9047\u3059\u308b\u554f\u984c\u3068\u3001\u305d\u306e\u5177\u4f53\u7684\u306a\u89e3\u6c7a\u65b9\u6cd5\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;exception&gt;\n#include &lt;string&gt;\n#include &lt;memory&gt;\n#include &lt;iostream&gt;\n#include &lt;functional&gt;\n\n\/\/ \u554f\u984c1: \u4f8b\u5916\u767a\u751f\u7b87\u6240\u306e\u7279\u5b9a\u304c\u56f0\u96e3\n\/\/ \u89e3\u6c7a\u7b56: \u8a73\u7d30\u306a\u4f8b\u5916\u60c5\u5831\u3092\u63d0\u4f9b\u3059\u308b\u30d9\u30fc\u30b9\u30af\u30e9\u30b9\nclass TracedException : public std::exception {\npublic:\n    TracedException(const std::string&amp; message, \n                   const char* file, \n                   int line,\n                   const char* function)\n        : message_(buildMessage(message, file, line, function)) {}\n\n    const char* what() const noexcept override {\n        return message_.c_str();\n    }\n\nprivate:\n    static std::string buildMessage(const std::string&amp; message,\n                                  const char* file,\n                                  int line,\n                                  const char* function) {\n        return std::string(file) + \":\" + std::to_string(line) + \n               \" in \" + function + \": \" + message;\n    }\n    std::string message_;\n};\n\n#define THROW_TRACED(message) \\\n    throw TracedException(message, __FILE__, __LINE__, __FUNCTION__)\n\n\/\/ \u554f\u984c2: \u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u306e\u9632\u6b62\nclass Resource {\npublic:\n    Resource() { std::cout &lt;&lt; \"\u30ea\u30bd\u30fc\u30b9\u78ba\u4fdd\\n\"; }\n    ~Resource() { std::cout &lt;&lt; \"\u30ea\u30bd\u30fc\u30b9\u89e3\u653e\\n\"; }\n    void doWork() { \n        throw std::runtime_error(\"\u4f5c\u696d\u4e2d\u306b\u30a8\u30e9\u30fc\u767a\u751f\"); \n    }\n};\n\nvoid badExample() {\n    Resource* r = new Resource();  \/\/ \u5371\u967a: \u4f8b\u5916\u6642\u306b\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\n    r-&gt;doWork();  \/\/ \u4f8b\u5916\u304c\u767a\u751f\n    delete r;     \/\/ \u3053\u306e\u884c\u306f\u5b9f\u884c\u3055\u308c\u306a\u3044\n}\n\nvoid goodExample() {\n    auto r = std::make_unique&lt;Resource&gt;();  \/\/ RAII: \u5b89\u5168\u306a\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\n    r-&gt;doWork();  \/\/ \u4f8b\u5916\u304c\u767a\u751f\u3057\u3066\u3082\u3001\u30ea\u30bd\u30fc\u30b9\u306f\u81ea\u52d5\u7684\u306b\u89e3\u653e\u3055\u308c\u308b\n}\n\n\/\/ \u554f\u984c3: \u4f8b\u5916\u306e\u4f1d\u64ad\u8ffd\u8de1\nclass ExceptionTracer {\npublic:\n    template&lt;typename Func&gt;\n    static void trace(const std::string&amp; context, Func&amp;&amp; func) {\n        try {\n            std::cout &lt;&lt; \"\u958b\u59cb: \" &lt;&lt; context &lt;&lt; \"\\n\";\n            func();\n            std::cout &lt;&lt; \"\u6b63\u5e38\u7d42\u4e86: \" &lt;&lt; context &lt;&lt; \"\\n\";\n        } catch (const std::exception&amp; e) {\n            std::cerr &lt;&lt; \"\u4f8b\u5916\u767a\u751f in \" &lt;&lt; context &lt;&lt; \": \" &lt;&lt; e.what() &lt;&lt; \"\\n\";\n            throw;  \/\/ \u4f8b\u5916\u3092\u518d\u30b9\u30ed\u30fc\n        }\n    }\n};<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-22\">\u52b9\u679c\u7684\u306a\u30ed\u30b0\u8a18\u9332\u306e\u5b9f\u88c5\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u30c7\u30d0\u30c3\u30b0\u3092\u52b9\u7387\u5316\u3059\u308b\u305f\u3081\u306e\u69cb\u9020\u5316\u3055\u308c\u305f\u30ed\u30b0\u8a18\u9332\u30b7\u30b9\u30c6\u30e0\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;fstream&gt;\n#include &lt;mutex&gt;\n#include &lt;sstream&gt;\n\nclass Logger {\npublic:\n    enum class Level { DEBUG, INFO, WARNING, ERROR };\n\n    static Logger&amp; instance() {\n        static Logger logger;\n        return logger;\n    }\n\n    void log(Level level, \n             const char* file, \n             int line, \n             const std::string&amp; message) {\n        std::lock_guard&lt;std::mutex&gt; lock(mutex_);\n\n        auto now = std::time(nullptr);\n        auto* timeinfo = std::localtime(&amp;now);\n\n        logFile_ &lt;&lt; std::put_time(timeinfo, \"[%Y-%m-%d %H:%M:%S] \")\n                &lt;&lt; getLevelString(level) &lt;&lt; \" \"\n                &lt;&lt; file &lt;&lt; \":\" &lt;&lt; line &lt;&lt; \" - \"\n                &lt;&lt; message &lt;&lt; std::endl;\n    }\n\n    void logException(const std::exception&amp; e,\n                     const char* file,\n                     int line) {\n        std::stringstream ss;\n        ss &lt;&lt; \"\u4f8b\u5916\u304c\u767a\u751f: \" &lt;&lt; e.what();\n        log(Level::ERROR, file, line, ss.str());\n    }\n\nprivate:\n    Logger() : logFile_(\"debug.log\", std::ios::app) {}\n\n    std::ofstream logFile_;\n    std::mutex mutex_;\n\n    const char* getLevelString(Level level) {\n        switch (level) {\n            case Level::DEBUG: return \"[DEBUG]\";\n            case Level::INFO: return \"[INFO]\";\n            case Level::WARNING: return \"[WARN]\";\n            case Level::ERROR: return \"[ERROR]\";\n            default: return \"[UNKNOWN]\";\n        }\n    }\n};\n\n\/\/ \u4f7f\u3044\u3084\u3059\u3044\u30de\u30af\u30ed\n#define LOG_DEBUG(msg) Logger::instance().log(Logger::Level::DEBUG, __FILE__, __LINE__, msg)\n#define LOG_ERROR(msg) Logger::instance().log(Logger::Level::ERROR, __FILE__, __LINE__, msg)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-23\">\u30c7\u30d0\u30c3\u30ac\u30fc\u3092\u4f7f\u7528\u3057\u305f\u4f8b\u5916\u306e\u8ffd\u8de1\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n\n\n\n<p>\u5b9f\u8df5\u7684\u306a\u30c7\u30d0\u30c3\u30b0\u624b\u6cd5\u306e\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class DebugHelper {\npublic:\n    static void setExceptionBreakpoint() {\n        #ifdef _DEBUG\n            \/\/ Windows\u306e\u5834\u5408\n            #ifdef _WIN32\n                __debugbreak();\n            \/\/ Unix\u7cfb\u306e\u5834\u5408\n            #else\n                raise(SIGTRAP);\n            #endif\n        #endif\n    }\n\n    static void debugExample() {\n        try {\n            LOG_DEBUG(\"\u51e6\u7406\u3092\u958b\u59cb\u3057\u307e\u3059\");\n\n            ExceptionTracer::trace(\"\u91cd\u8981\u306a\u64cd\u4f5c\", []() {\n                auto resource = std::make_unique&lt;Resource&gt;();\n                resource-&gt;doWork();\n            });\n\n        } catch (const std::exception&amp; e) {\n            LOG_ERROR(std::string(\"\u30a8\u30e9\u30fc\u304c\u767a\u751f: \") + e.what());\n            setExceptionBreakpoint();  \/\/ \u30c7\u30d0\u30c3\u30b0\u6642\u306b\u505c\u6b62\n            throw;\n        }\n    }\n};\n\n\/\/ \u30c7\u30d0\u30c3\u30b0\u6642\u306e\u5b9f\u88c5\u4f8b\nvoid debuggingDemo() {\n    try {\n        LOG_DEBUG(\"\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u59cb\u3057\u307e\u3059\");\n\n        ExceptionTracer::trace(\"\u521d\u671f\u5316\u51e6\u7406\", []() {\n            \/\/ \u521d\u671f\u5316\u51e6\u7406\n            THROW_TRACED(\"\u521d\u671f\u5316\u306b\u5931\u6557\u3057\u307e\u3057\u305f\");\n        });\n\n    } catch (const TracedException&amp; e) {\n        Logger::instance().logException(e, __FILE__, __LINE__);\n        \/\/ \u4f8b\u5916\u60c5\u5831\u3092\u78ba\u8a8d\u3057\u3066\u30c7\u30d0\u30c3\u30b0\n        std::cerr &lt;&lt; \"\u8a73\u7d30\u306a\u30a8\u30e9\u30fc\u60c5\u5831: \" &lt;&lt; e.what() &lt;&lt; std::endl;\n    }\n}<\/pre>\n\n\n\n<p>\u5b9f\u8df5\u7684\u306a\u30c7\u30d0\u30c3\u30b0\u306e\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f8b\u5916\u306e\u30c8\u30ec\u30fc\u30b9<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u767a\u751f\u5834\u6240\u306e\u6b63\u78ba\u306a\u7279\u5b9a<\/li>\n\n\n\n<li>\u30b3\u30fc\u30eb\u30b9\u30bf\u30c3\u30af\u306e\u4fdd\u6301<\/li>\n\n\n\n<li>\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u60c5\u5831\u306e\u8a18\u9332<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ed\u30b0\u8a18\u9332\u306e\u91cd\u8981\u6027<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u69cb\u9020\u5316\u3055\u308c\u305f\u30ed\u30b0\u30d5\u30a9\u30fc\u30de\u30c3\u30c8<\/li>\n\n\n\n<li>\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3068\u4f4d\u7f6e\u60c5\u5831\u306e\u8a18\u9332<\/li>\n\n\n\n<li>\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306a\u5b9f\u88c5<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30c7\u30d0\u30c3\u30b0\u6642\u306e\u6ce8\u610f\u70b9<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6761\u4ef6\u4ed8\u304d\u30d6\u30ec\u30fc\u30af\u30dd\u30a4\u30f3\u30c8\u306e\u6d3b\u7528<\/li>\n\n\n\n<li>\u4f8b\u5916\u767a\u751f\u6642\u306e\u81ea\u52d5\u505c\u6b62<\/li>\n\n\n\n<li>\u30ea\u30bd\u30fc\u30b9\u30ea\u30fc\u30af\u306e\u76e3\u8996<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u624b\u6cd5\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u4f8b\u5916\u306b\u95a2\u9023\u3059\u308b\u554f\u984c\u3092\u52b9\u7387\u7684\u306b\u7279\u5b9a\u3057\u3001\u89e3\u6c7a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-24\">\u30c1\u30fc\u30e0\u958b\u767a\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406\u306e\u6a19\u6e96\u5316<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-25\">\u4f8b\u5916\u51e6\u7406\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u306e\u9032\u3081\u65b9<\/h3>\n\n\n\n<p>\u30c1\u30fc\u30e0\u5168\u4f53\u3067\u4e00\u8cab\u3057\u305f\u4f8b\u5916\u51e6\u7406\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306e\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u4f8b\u3092\u793a\u3057\u307e\u3059\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ 1. \u6a19\u6e96\u7684\u306a\u4f8b\u5916\u968e\u5c64\u306e\u5b9a\u7fa9\nnamespace ProjectExceptions {\n    \/\/ \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5171\u901a\u306e\u57fa\u5e95\u4f8b\u5916\u30af\u30e9\u30b9\n    class ProjectException : public std::runtime_error {\n    public:\n        ProjectException(const std::string&amp; message, \n                        const char* file, \n                        int line,\n                        const std::string&amp; componentName)\n            : std::runtime_error(formatMessage(message, file, line, componentName))\n            , rawMessage_(message)\n            , file_(file)\n            , line_(line)\n            , componentName_(componentName) {}\n\n        \/\/ \u5404\u7a2e\u60c5\u5831\u3078\u306e\u30a2\u30af\u30bb\u30b5\n        const std::string&amp; getRawMessage() const { return rawMessage_; }\n        const std::string&amp; getFile() const { return file_; }\n        int getLine() const { return line_; }\n        const std::string&amp; getComponent() const { return componentName_; }\n\n    private:\n        static std::string formatMessage(const std::string&amp; message,\n                                       const char* file,\n                                       int line,\n                                       const std::string&amp; componentName) {\n            std::ostringstream oss;\n            oss &lt;&lt; \"[\" &lt;&lt; componentName &lt;&lt; \"] \"\n                &lt;&lt; file &lt;&lt; \":\" &lt;&lt; line &lt;&lt; \" - \"\n                &lt;&lt; message;\n            return oss.str();\n        }\n\n        std::string rawMessage_;\n        std::string file_;\n        int line_;\n        std::string componentName_;\n    };\n\n    \/\/ \u6a5f\u80fd\u5225\u306e\u4f8b\u5916\u30af\u30e9\u30b9\n    #define DECLARE_EXCEPTION(ExceptionName) \\\n    class ExceptionName : public ProjectException { \\\n    public: \\\n        ExceptionName(const std::string&amp; message, \\\n                     const char* file, \\\n                     int line) \\\n            : ProjectException(message, file, line, #ExceptionName) {} \\\n    }\n\n    DECLARE_EXCEPTION(ValidationException);\n    DECLARE_EXCEPTION(DatabaseException);\n    DECLARE_EXCEPTION(NetworkException);\n    DECLARE_EXCEPTION(ConfigurationException);\n}\n\n\/\/ 2. \u4f8b\u5916\u3092\u30b9\u30ed\u30fc\u3059\u308b\u305f\u3081\u306e\u6a19\u6e96\u7684\u306a\u30de\u30af\u30ed\n#define THROW_PROJECT_EXCEPTION(ExceptionType, message) \\\n    throw ProjectExceptions::ExceptionType(message, __FILE__, __LINE__)\n\n\/\/ 3. \u4f8b\u5916\u51e6\u7406\u306e\u6a19\u6e96\u30d1\u30bf\u30fc\u30f3\nclass StandardizedExceptionHandling {\npublic:\n    template&lt;typename Func&gt;\n    static auto executeWithStandardHandling(\n        const std::string&amp; operationName,\n        Func&amp;&amp; operation) -&gt; decltype(operation())\n    {\n        try {\n            Logger::debug() &lt;&lt; \"\u958b\u59cb: \" &lt;&lt; operationName;\n            auto result = operation();\n            Logger::debug() &lt;&lt; \"\u5b8c\u4e86: \" &lt;&lt; operationName;\n            return result;\n        }\n        catch (const ProjectExceptions::ProjectException&amp; e) {\n            Logger::error() &lt;&lt; \"\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f8b\u5916: \" &lt;&lt; e.what();\n            throw;  \/\/ \u518d\u30b9\u30ed\u30fc\n        }\n        catch (const std::exception&amp; e) {\n            Logger::error() &lt;&lt; \"\u6a19\u6e96\u4f8b\u5916: \" &lt;&lt; e.what();\n            THROW_PROJECT_EXCEPTION(\n                ValidationException, \n                std::string(\"\u4e88\u671f\u3057\u306a\u3044\u30a8\u30e9\u30fc: \") + e.what()\n            );\n        }\n    }\n};<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-26\">\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3067\u306e\u30c1\u30a7\u30c3\u30af\u30dd\u30a4\u30f3\u30c8<\/h3>\n\n\n\n<p>\u4f8b\u5916\u51e6\u7406\u306b\u95a2\u3059\u308b\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u306e\u305f\u3081\u306e\u30c1\u30a7\u30c3\u30af\u30ea\u30b9\u30c8\u5b9f\u88c5\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u652f\u63f4\u30af\u30e9\u30b9\nclass ExceptionReviewHelper {\npublic:\n    \/\/ RAII\u9055\u53cd\u306e\u691c\u51fa\n    static void checkResourceManagement() {\n        \/\/ \u60aa\u3044\u4f8b\n        void badExample() {\n            FILE* file = fopen(\"test.txt\", \"r\");  \/\/ \u8981\u30c1\u30a7\u30c3\u30af: RAII\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\n            \/\/ ...\n            fclose(file);\n        }\n\n        \/\/ \u826f\u3044\u4f8b\n        void goodExample() {\n            std::ifstream file(\"test.txt\");  \/\/ OK: RAII\u3092\u4f7f\u7528\n            \/\/ ...\n        }  \/\/ \u81ea\u52d5\u7684\u306b\u30af\u30ed\u30fc\u30ba\n    }\n\n    \/\/ \u4f8b\u5916\u5b89\u5168\u6027\u306e\u30c1\u30a7\u30c3\u30af\n    class ExceptionSafetyChecker {\n    public:\n        \/\/ \u57fa\u672c\u4f8b\u5916\u5b89\u5168\u6027\u306e\u4f8b\n        void demonstrateBasicGuarantee() {\n            std::vector&lt;std::unique_ptr&lt;Resource&gt;&gt; resources;\n            \/\/ OK: \u4f8b\u5916\u304c\u767a\u751f\u3057\u3066\u3082\u65e2\u5b58\u306e\u30ea\u30bd\u30fc\u30b9\u306f\u5b89\u5168\n            resources.push_back(std::make_unique&lt;Resource&gt;());\n        }\n\n        \/\/ \u5f37\u3044\u4f8b\u5916\u5b89\u5168\u6027\u306e\u4f8b\n        void demonstrateStrongGuarantee() {\n            std::vector&lt;Resource&gt; resources;\n            \/\/ \u4e00\u6642\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3057\u3066\u5f37\u3044\u4f8b\u5916\u5b89\u5168\u6027\u3092\u78ba\u4fdd\n            Resource temp;\n            \/\/ \u6210\u529f\u3057\u305f\u5834\u5408\u306e\u307f\u8ffd\u52a0\n            resources.push_back(std::move(temp));\n        }\n    };\n};<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-27\">\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u5316\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/h3>\n\n\n\n<p>\u4f8b\u5916\u51e6\u7406\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u5316\u4f8b\u3068\u81ea\u52d5\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u751f\u6210\u306e\u652f\u63f4\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/**\n * @brief \u4f8b\u5916\u4ed5\u69d8\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u5316\u4f8b\n * \n * @throws ValidationException \u5165\u529b\u5024\u304c\u7121\u52b9\u306a\u5834\u5408\n * @throws DatabaseException \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u306b\u5931\u6557\u3057\u305f\u5834\u5408\n * @throws NetworkException \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u63a5\u7d9a\u306b\u554f\u984c\u304c\u767a\u751f\u3057\u305f\u5834\u5408\n * \n * @note \u3053\u306e\u30af\u30e9\u30b9\u306f\u5f37\u3044\u4f8b\u5916\u5b89\u5168\u6027\u3092\u4fdd\u8a3c\u3057\u307e\u3059\n *\/\nclass DocumentedClass {\npublic:\n    \/**\n     * @brief \u30c7\u30fc\u30bf\u3092\u51e6\u7406\u3059\u308b\u95a2\u6570\n     * @param data \u51e6\u7406\u5bfe\u8c61\u306e\u30c7\u30fc\u30bf\n     * @throws ValidationException \u30c7\u30fc\u30bf\u304c NULL \u306e\u5834\u5408\n     * @throws DatabaseException \u30c7\u30fc\u30bf\u306e\u4fdd\u5b58\u306b\u5931\u6557\u3057\u305f\u5834\u5408\n     *\/\n    void processData(const Data* data) {\n        if (!data) {\n            THROW_PROJECT_EXCEPTION(ValidationException, \"\u30c7\u30fc\u30bf\u304cNULL\u3067\u3059\");\n        }\n\n        try {\n            database_.store(*data);\n        } catch (const DatabaseError&amp; e) {\n            THROW_PROJECT_EXCEPTION(\n                DatabaseException,\n                std::string(\"\u30c7\u30fc\u30bf\u306e\u4fdd\u5b58\u306b\u5931\u6557: \") + e.what()\n            );\n        }\n    }\n\nprivate:\n    Database database_;\n};\n\n\/\/ \u4f8b\u5916\u4ed5\u69d8\u306e\u81ea\u52d5\u53ce\u96c6\u3092\u652f\u63f4\u3059\u308b\u30de\u30af\u30ed\n#define DOCUMENT_EXCEPTIONS(func, ...) \\\n    static const std::vector&lt;std::string&gt; func##_exceptions = {__VA_ARGS__}\n\n\/\/ \u4f7f\u7528\u4f8b\nclass AutoDocumented {\npublic:\n    void riskyOperation();\n    DOCUMENT_EXCEPTIONS(riskyOperation, \n        \"ValidationException\", \n        \"DatabaseException\"\n    );\n};<\/pre>\n\n\n\n<p>\u30c1\u30fc\u30e0\u958b\u767a\u3067\u306e\u4f8b\u5916\u51e6\u7406\u6a19\u6e96\u5316\u306e\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u306e\u6574\u5099<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u660e\u78ba\u306a\u4f8b\u5916\u968e\u5c64\u306e\u5b9a\u7fa9<\/li>\n\n\n\n<li>\u6a19\u6e96\u7684\u306a\u30b9\u30ed\u30fc\u65b9\u6cd5\u306e\u78ba\u7acb<\/li>\n\n\n\n<li>\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5f62\u5f0f\u7d71\u4e00<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u306e\u91cd\u70b9\u9805\u76ee<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAII\u539f\u5247\u306e\u9075\u5b88<\/li>\n\n\n\n<li>\u4f8b\u5916\u5b89\u5168\u6027\u306e\u78ba\u8a8d<\/li>\n\n\n\n<li>\u30ea\u30bd\u30fc\u30b9\u7ba1\u7406\u306e\u691c\u8a3c<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u5316\u306e\u8981\u4ef6<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5916\u4ed5\u69d8\u306e\u660e\u78ba\u306a\u8a18\u8ff0<\/li>\n\n\n\n<li>\u4f8b\u5916\u5b89\u5168\u6027\u30ec\u30d9\u30eb\u306e\u660e\u793a<\/li>\n\n\n\n<li>\u81ea\u52d5\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u751f\u6210\u306e\u6d3b\u7528<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u6a19\u6e96\u5316\u306b\u3088\u308a\u3001\u30c1\u30fc\u30e0\u5168\u4f53\u3067\u4e00\u8cab\u6027\u306e\u3042\u308b\u3001\u4fdd\u5b88\u6027\u306e\u9ad8\u3044\u4f8b\u5916\u51e6\u7406\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Warning: Undefined array key &#8220;is_admin&#8221; in \/home\/xs392991\/dexall.co.jp\/public_html\/articles\/wp-content\/themes\/ &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":{"0":"post-2118","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-cpp","7":"nothumb"},"_links":{"self":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2118"}],"version-history":[{"count":1,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2118\/revisions"}],"predecessor-version":[{"id":2119,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=\/wp\/v2\/posts\/2118\/revisions\/2119"}],"wp:attachment":[{"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dexall.co.jp\/articles\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}