{"id":7049,"date":"2019-11-17T15:56:56","date_gmt":"2019-11-17T06:56:56","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=7049"},"modified":"2023-05-27T22:34:22","modified_gmt":"2023-05-27T13:34:22","slug":"%e3%80%90ruby%e3%80%91%e4%be%8b%e5%a4%96%e5%87%a6%e7%90%86","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=7049","title":{"rendered":"\u3010Ruby\u3011\u4f8b\u5916\u51e6\u7406"},"content":{"rendered":"<h2>Ruby\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>\u4f8b\u5916\u3092\u88dc\u8db3\u3057\u306a\u3044\u5834\u5408\u306f\u3001Ruby\u3067\u306f\u305d\u3053\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u4e2d\u65ad\u3059\u308b<\/strong><\/span>\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u306a\u304a\u3001\u88dc\u8db3\u3057\u305f\u3068\u3057\u3066\u3082\u88dc\u8db3\u5f8c\u306e\u52d5\u4f5c\u3092\u7d42\u3048\u305f\u3089\u305d\u3053\u3067\u51e6\u7406\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002\uff09<\/p>\n<h2>\u69cb\u6587<\/h2>\n<pre class=\"lang:default decode:true\">begin\r\n  #\u4f8b\u5916\u304c\u8d77\u3053\u308a\u5f97\u308b\u51e6\u7406\r\nrescue \u88dc\u8db3\u3057\u305f\u3044\u4f8b\u5916\u306e\u7a2e\u985e1,\u88dc\u8db3\u3057\u305f\u3044\u4f8b\u5916\u306e\u7a2e\u985e2 =&gt; e(\u4f8b\u5916\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u683c\u7d0d\u3059\u308b\u5909\u6570)\r\n  #\u4f8b\u5916\u51e6\u7406 \r\n  #begin\u3092\u3082\u3046\u4e00\u5ea6\u884c\u3044\u305f\u3044\u5834\u5408\u306b\u4f7f\u7528\uff08\u305d\u306e\u5834\u5408\u306f\u4f8b\u5916\u51e6\u7406\u5185\u3067\u4f8b\u5916\u304c\u8d77\u304d\u306a\u3044\u3088\u3046\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002\uff09\r\n\u3000retry\r\nensure\r\n  #\u4f8b\u5916\u306e\u767a\u751f\u6709\u7121\u306b\u95a2\u308f\u3089\u305a\u5b9f\u884c\u3057\u305f\u3044\u51e6\u7406\r\nend<\/pre>\n<h3>retry\u306e\u6ce8\u610f<\/h3>\n<p>retry\u3092\u3059\u308c\u3070begin\u3092\u3082\u3046\u4e00\u5ea6\u5b9f\u884c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001<span style=\"color: #ff0000;\"><strong>rescue\u5185\u306e\u4f8b\u5916\u51e6\u7406\u306b\u3066\u30a8\u30e9\u30fc\u3092\u89e3\u6d88\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u304b\u306a\u3051\u308c\u3070\u6c38\u9060\u306b\u51e6\u7406\u304c\u7d99\u7d9a\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>ensure<\/h3>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u9589\u3058\u5fd8\u308c\u3092\u9632\u3050\u305f\u3081\u306b\u4f7f\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<h2>\u88dc\u8db3\u3057\u305f\u3044\u4f8b\u5916\u306e\u7a2e\u985e<\/h2>\n<p>\u3053\u308c\u3092resuce\u3067\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u8a72\u5f53\u306e\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306e\u307f\u4f8b\u5916\u51e6\u7406\u304c\u884c\u308f\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u5177\u4f53\u4f8b<\/h3>\n<ul>\n<li>ZeroDivisionError<\/li>\n<li>NoMethodError<\/li>\n<\/ul>\n<h2>\u4f8b\u5916\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h2>\n<p>resucue\u6587\u3067\u4f8b\u5916\u3092\u88dc\u8db3\u3059\u308b\u3068\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002\u4e0a\u8a18\u4f8b\u3067\u8a00\u3048\u3070<span style=\"color: #ff0000;\"><strong>\u300ce\u300d<\/strong><\/span>\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<h3>message\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u4f8b\u5916\u767a\u751f\u6642\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u51fa\u529b\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>class\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u4f8b\u5916\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u7a2e\u985e\u3092\u8868\u793a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>backtrace\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u4f8b\u5916\u306e\u30d0\u30c3\u30af\u30c8\u30ec\u30fc\u30b9\u60c5\u5831\u3092\u51fa\u529b\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>full_message\u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u4f8b\u5916\u306b\u95a2\u3059\u308b\u6574\u5f62\u3055\u308c\u305f\u60c5\u5831\u3092\u51fa\u529b\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n<h2>\u4f8b\u5916\u3092\u610f\u56f3\u7684\u306b\u767a\u751f\u3055\u305b\u308b\u3002<\/h2>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308c\u3070\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4efb\u610f\u306e\u7b87\u6240\u3067\u4f8b\u5916\u3092<span style=\"color: #ff0000;\"><strong>\u610f\u56f3\u7684\u306b\u767a\u751f\u3055\u305b\u308b<\/strong><\/span>\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">raise \u4f8b\u5916\u306e\u7a2e\u985e(ArgumentError\u7b49),\"\u4f8b\u5916\u30e1\u30c3\u30bb\u30fc\u30b8\u5185\u5bb9\"<\/pre>\n<p>\u306a\u304a\u3001\u4f8b\u5916\u306e\u7a2e\u985e\u3092\u6307\u5b9a\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u306f<span style=\"color: #ff0000;\"><strong>\u300cRuntimeError\u300d<\/strong><\/span>\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<h2>\u72ec\u81ea\u4f8b\u5916<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>\u300cStandardError\u300d\u30af\u30e9\u30b9<\/strong><\/span>\u3092\u72ec\u81ea\u4f8b\u5916\u30af\u30e9\u30b9\u306b\u7d99\u627f\u3055\u305b\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<h2>\u4f8b\u5916\u306e\u5b9f\u88c5\u65b9\u91dd<\/h2>\n<p>\u57fa\u672c\u7684\u306b\u306f\u3001<span style=\"color: #ff0000;\"><strong>rescue\u3092\u5b89\u6613\u306b\u4f7f\u308f\u306a\u3044\u3088\u3046\u306b\u3057\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u3089\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4e2d\u65ad\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<p>\u307e\u305f\u3001\u6700\u8fd1\u3067\u3042\u308c\u3070Rails\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304c\u81ea\u52d5\u3067\u4f8b\u5916\u51e6\u7406\u307e\u3067\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u81ea\u5206\u3067rescue\u3067\u51e6\u7406\u3092\u66f8\u304b\u306a\u304f\u3066\u3082\u59d4\u306d\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h3>rescue\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3044\u5834\u5408<\/h3>\n<p>\u305f\u3060\u3001\u4f8b\u5916\u306f\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001DB\u3078\u306e\u767b\u9332\u51e6\u7406\u3067\u4e00\u90e8\u304c\u5931\u6557\u3057\u305f\u304b\u3089\u3068\u8a00\u3063\u3066\u5168\u4f53\u306e\u767b\u9332\u3092\u4e2d\u65ad\u3059\u308b\u3068\u3044\u3046\u306e\u3067\u306f\u8981\u4ef6\u7684\u306b\u56f0\u308b\u30b1\u30fc\u30b9\u3068\u304b\u3082\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306f\u4f8b\u5916\u304c\u767a\u751f\u3057\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u4e2d\u65ad\u3059\u308b\u3068\u56f0\u308b\u306e\u3067rescue\u3067\u51e6\u7406\u3092\u7d9a\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u305f\u3060\u3001\u305d\u306e\u5834\u5408\u3067\u3082<span style=\"color: #ff0000;\"><strong>\u5f8c\u3067\u539f\u56e0\u89e3\u6790\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u30af\u30e9\u30b9\u540d\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3001\u30d0\u30c3\u30af\u30c8\u30ec\u30fc\u30b9\u60c5\u5831\u3060\u3051\u306f\u6700\u4f4e\u9650\u51fa\u529b\u3055\u305b\u308b<\/strong><\/span>\u3088\u3046\u306a\u4ed5\u69d8\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Ruby\u306b\u304a\u3051\u308b\u4f8b\u5916\u51e6\u7406 \u4f8b\u5916\u3092\u88dc\u8db3\u3057\u306a\u3044\u5834\u5408\u306f\u3001Ruby\u3067\u306f\u305d\u3053\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u4e2d\u65ad\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u306a\u304a\u3001\u88dc\u8db3\u3057\u305f\u3068\u3057\u3066\u3082\u88dc\u8db3\u5f8c\u306e\u52d5\u4f5c\u3092\u7d42\u3048\u305f\u3089\u305d\u3053\u3067\u51e6\u7406\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002\uff09 \u69cb\u6587 begin #\u4f8b\u5916\u304c\u8d77\u3053\u308a\u5f97\u308b\u51e6\u7406  [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[48],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7049"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7049"}],"version-history":[{"count":14,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7049\/revisions"}],"predecessor-version":[{"id":20476,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7049\/revisions\/20476"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7049"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}