{"id":3483,"date":"2013-11-25T11:52:48","date_gmt":"2013-11-25T02:52:48","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=3483"},"modified":"2018-11-14T16:33:53","modified_gmt":"2018-11-14T07:33:53","slug":"road-to-exception-safety","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2013\/11\/25\/road-to-exception-safety\/","title":{"rendered":"\u4f8b\u5916\u5b89\u5168\u3078\u306e\u9053 - Road to Exception Safety"},"content":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n
<\/p>\n
\u300c\u4f8b\u5916\u5b89\u5168 (Exception Safety)\u300d\u3068\u3044\u3046\u8a00\u8449\u3092\u3054\u5b58\u77e5\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n
<\/p>\n
\u9031\u672b\u3001\u672c\u306e\u6574\u7406\u3092\u3057\u3066\u3044\u305f\u3068\u304d\u306b\u300cExceptional C++\u300d\u3068\u3044\u3046\u672c\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002C++ \u306e\u30a4\u30c7\u30a3\u30aa\u30e0\u96c6\u3068\u3044\u3063\u305f\u611f\u3058\u306e\u672c\u306a\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u4e2d\u306b\u767b\u5834\u3059\u308b\u300c\u4f8b\u5916\u5b89\u5168\u300d\u3068\u3044\u3046\u8a00\u8449\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
<\/p>\n
\u300c\u4f8b\u5916\u5b89\u5168\u300d\u3068\u306f\u3001\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u306b\u9069\u5207\u306b\u51e6\u7406\u3055\u308c\u308b\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u8a00\u8449\u3067\u3059\u3002\u300c\u9069\u5207\u306b\u300d\u3068\u306f\u3001\u30ea\u30bd\u30fc\u30b9\u30ea\u30fc\u30af\u304c\u767a\u751f\u3057\u306a\u3044\u3053\u3068\u3084\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5185\u90e8\u72b6\u614b\u306e\u6574\u5408\u6027\u304c\u4fdd\u305f\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n
\u300c\u666e\u6bb5\u304b\u3089\u610f\u8b58\u3057\u3066\u308b\u3088\u300d\u3068\u3044\u3046\u65b9\u3082\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u300c\u805e\u3044\u305f\u3053\u3068\u304c\u7121\u304b\u3063\u305f\u300d\u3068\u3044\u3046\u65b9\u306f\u3001\u4f8b\u5916\u5b89\u5168\u3068\u3044\u3046\u8003\u3048\u65b9\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u3067\u3001\u4eca\u307e\u3067\u3088\u308a\u54c1\u8cea\u306e\u826f\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u3051\u308b\u3088\u3046\u306b\u306a\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n
Web\u4e0a\u306e\u30ea\u30bd\u30fc\u30b9\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u306b\u8a18\u8f09\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n
\u4e0a\u8a18\u30da\u30fc\u30b8\u306e\u30bf\u30a4\u30c8\u30eb\u3092\u65e5\u672c\u8a9e\u306b\u3059\u308b\u3068\u300c\u6c4e\u7528\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u304a\u3051\u308b\u4f8b\u5916\u5b89\u5168\u6027\u300d\u3067\u3059\u3002C++ \u3067\u6c4e\u7528\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306e\u4f8b\u5916\u306e\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u306b\u3064\u3044\u3066\u306e\u8a71\u3067\u3059\u3002\u305d\u306e\u3068\u304d\u306b\u30dd\u30a4\u30f3\u30c8\u3068\u306a\u308b\u8003\u3048\u65b9\u304c\u300c\u4f8b\u5916\u5b89\u5168\u300d\u3067\u3059\u3002<\/p>\n
<\/p>\n
\u4f8b\u5916\u5b89\u5168\u306b\u306f\u4ee5\u4e0b\u306b\u6319\u3052\u308b\u4fdd\u8a3c\u30ec\u30d9\u30eb\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n
\u3053\u308c\u3089\u306f\u5305\u542b\u95a2\u4fc2\u306b\u3042\u308a\u3001\u300c\u4f8b\u5916\u3092\u6295\u3052\u306a\u3044\u4fdd\u8a3c\u300d\u3092\u6e80\u305f\u3057\u3066\u3044\u308c\u3070\u81ea\u52d5\u7684\u306b\u300c\u5f37\u3044\u4fdd\u8a3c\u300d\u3092\u6e80\u305f\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u300c\u5f37\u3044\u4fdd\u8a3c\u300d\u3092\u6e80\u305f\u3059\u306e\u3067\u3042\u308c\u3070\u300c\u57fa\u672c\u7684\u4fdd\u8a3c\u300d\u3092\u6e80\u305f\u3057\u307e\u3059\u3002<\/p>\n
<\/p>\n
\u57fa\u672c\u7684\u4fdd\u8a3c\u3092\u6e80\u305f\u3059\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u547c\u3073\u51fa\u3057\u306b\u3088\u3063\u3066\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306b\u4ee5\u4e0b\u306e\u3053\u3068\u304c\u4fdd\u8a3c\u3055\u308c\u307e\u3059\u3002<\/p>\n
<\/p>\n
\u5f37\u3044\u4fdd\u8a3c\u3092\u6e80\u305f\u3059\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30e1\u30bd\u30c3\u30c9\u5185\u3067\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306b\u4ee5\u4e0b\u306e\u3053\u3068\u304c\u4fdd\u8a3c\u3055\u308c\u307e\u3059\u3002<\/p>\n
\u3053\u308c\u306f\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u304a\u3051\u308b\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3068\u540c\u3058\u6027\u8cea\u3067\u3059\u3002<\/p>\n
\u57fa\u672c\u7684\u4fdd\u8a3c\u306f\u666e\u901a\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u3044\u3066\u3082\u6e80\u305f\u305b\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u304c\u3001\u5f37\u3044\u4fdd\u8a3c\u306f\u610f\u8b58\u3057\u306a\u3051\u308c\u3070\u6e80\u305f\u305b\u306a\u3044\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n
\u4f8b\u3048\u3070\u30e1\u30bd\u30c3\u30c9\u5185\u3067\u526f\u4f5c\u7528\u306e\u3042\u308b\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u308b\u5834\u5408\u3001\u610f\u8b58\u3057\u3066\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u306a\u3051\u308c\u3070\u5f37\u3044\u4fdd\u8a3c\u3092\u6e80\u305f\u305b\u306a\u3044\u3053\u3068\u304c\u591a\u3044\u3067\u3057\u3087\u3046\u3002\u753b\u9762\u306b\u5370\u5b57\u3057\u305f\u5f8c\u306b\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306a\u3069\u3001\u5f37\u3044\u4fdd\u8a3c\u3092\u6e80\u305f\u3059\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u30b1\u30fc\u30b9\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n
<\/p>\n
\u4f8b\u5916\u3092\u6295\u3052\u306a\u3044\u4fdd\u8a3c\u306b\u3064\u3044\u3066\u306f\u8aac\u660e\u4e0d\u8981\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u3053\u308c\u3092\u6e80\u305f\u3059\u30e1\u30bd\u30c3\u30c9\u306f\u4ee5\u4e0b\u306e\u3053\u3068\u3092\u4fdd\u8a3c\u3057\u307e\u3059\u3002<\/p>\n
\u3053\u308c\u306f\u56db\u5247\u6f14\u7b97\u3057\u304b\u884c\u308f\u306a\u3044\u3088\u3046\u306a\u4e00\u90e8\u306e\u30e1\u30bd\u30c3\u30c9\u3060\u3051\u304c\u6e80\u305f\u3059\u3053\u3068\u306e\u3067\u304d\u308b\u3001\u6700\u3082\u5f37\u3044\u4fdd\u8a3c\u30ec\u30d9\u30eb\u3067\u3059\u3002<\/p>\n
<\/p>\n
\u4f8b\u3068\u3057\u3066\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n
class MyLogger\r\n\r\n def initialize(log_file_path)\r\n @file = File.open(log_file_path, 'a')\r\n @file.sync = true\r\n end\r\n\r\n def log(message)\r\n @file.puts message\r\n end\r\n\r\n def reopen(log_file_path)\r\n @file.close\r\n @file = File.open(log_file_path, 'a') # \u30d5\u30a1\u30a4\u30eb\u304c\u958b\u3051\u306a\u304b\u3063\u305f\u3089?\r\n @file.sync = true\r\n end\r\n\r\nend<\/pre>\n\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u30ed\u30b0\u51fa\u529b\u3059\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u51fa\u529b\u5148\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u3001log \u30e1\u30bd\u30c3\u30c9\u3067\u30ed\u30b0\u51fa\u529b\u3057\u307e\u3059\u3002\u307e\u305f\u3001reopen \u30e1\u30bd\u30c3\u30c9\u3067\u51fa\u529b\u5148\u30d5\u30a1\u30a4\u30eb\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n
\u300c# \u30d5\u30a1\u30a4\u30eb\u304c\u958b\u3051\u306a\u304b\u3063\u305f\u3089?\u300d\u3068\u30b3\u30e1\u30f3\u30c8\u3057\u3066\u3044\u308b\u90e8\u5206\u3092\u898b\u3066\u3044\u305f\u3060\u304d\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u3053\u3053\u3067\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u3051\u305a\u306b\u4f8b\u5916\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3046\u3068\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n
\u76f4\u524d\u306e\u884c\u3067 @file.close \u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3082\u3046 log \u30e1\u30bd\u30c3\u30c9\u3067\u30ed\u30b0\u3092\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u3064\u307e\u308a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5185\u90e8\u304c\u6574\u5408\u6027\u306e\u53d6\u308c\u3066\u3044\u306a\u3044\u72b6\u614b\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u57fa\u672c\u7684\u4fdd\u8a3c\u3092\u6e80\u305f\u3057\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n
\u3053\u308c\u306a\u3089\u3069\u3046\u3067\u3057\u3087\u3046\u3002<\/p>\n
class MyLogger\r\n\r\n def initialize(log_file_path)\r\n @file = File.open(log_file_path, 'a')\r\n @file.sync = true\r\n end\r\n\r\n def log(message)\r\n @file.puts message\r\n end\r\n\r\n def reopen(log_file_path)\r\n # (1) \u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u3092\u5148\u306b\u958b\u304f.\r\n new_file = File.open(log_file_path, 'a')\r\n new_file.sync = true\r\n\r\n # (2) \u958b\u3044\u3066\u3044\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058, @file \u306e\u5024\u3092\u5909\u3048\u308b.\r\n @file.close\r\n @file = new_file\r\n end\r\n\r\nend<\/pre>\n\u30b3\u30e1\u30f3\u30c8\u306b\u66f8\u3044\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u304b\u3089\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570\u306e @file \u3092\u66f4\u65b0\u3059\u308b\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n
\u3053\u308c\u3067\u57fa\u672c\u7684\u4fdd\u8a3c\u304c\u6e80\u305f\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u304b\u3068\u3044\u3046\u3068\u3001\u30fb\u30fb\u30fb\u6b8b\u5ff5\u306a\u304c\u3089\u305d\u3046\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002@file.close \u3067\u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u304b\u3089\u3067\u3059\u3002\u305d\u306e\u5834\u5408\u3001new_file \u304c close \u3055\u308c\u306a\u3044\u305f\u3081\u3001\u30ea\u30bd\u30fc\u30b9\u30ea\u30fc\u30af\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n
\u306a\u304b\u306a\u304b\u96e3\u3057\u3044\u3067\u3059\u306d\u3002\u4eca\u5ea6\u306f\u3069\u3046\u3067\u3057\u3087\u3046\u3002<\/p>\n
class MyLogger\r\n\r\n def initialize(log_file_path)\r\n @file = File.open(log_file_path, 'a')\r\n @file.sync = true\r\n end\r\n\r\n def log(message)\r\n @file.puts message\r\n end\r\n\r\n def reopen(log_file_path)\r\n new_file = File.open(log_file_path, 'a')\r\n new_file.sync = true\r\n\r\n begin\r\n @file.close\r\n @file = new_file\r\n rescue\r\n new_file.close\r\n raise\r\n end\r\n end\r\n\r\nend<\/pre>\n\u4eca\u5ea6\u306f @file.close \u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306b new_file.close \u3059\u308b\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u3067\u30ea\u30bd\u30fc\u30b9\u30ea\u30fc\u30af\u306f\u7121\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n
\u30b3\u30fc\u30c9\u3092\u898b\u3066\u3044\u305f\u3060\u304f\u3068\u5206\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u4f8b\u5916\u5b89\u5168\u306b\u3059\u308b\u306e\u3063\u3066\u5927\u5909\u3067\u3059\u3088\u306d\u3002\u55c5\u899a\u3092\u50cd\u304b\u305b\u3066\u300c\u3053\u308c\u306f\u30e4\u30d0\u30a4\u300d\u3068\u3044\u3046\u90e8\u5206\u3092\u300cbegin \uff5e rescue \uff5e end\u300d\u3067\u56f2\u3063\u3066\u3044\u304f\u3068\u3002<\/p>\n
\u3053\u308c\u306b\u5bfe\u3059\u308b\u7b54\u3048\u3068\u3057\u3066\u306f\u300c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5909\u66f4\u4e0d\u80fd (immutable) \u306b\u305b\u3088\u300d\u3067\u3042\u3063\u305f\u308a\u300c\u5185\u90e8\u72b6\u614b\u3092 swap \u305b\u3088\u300d\u3067\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3064\u3044\u3066\u306f\u307e\u305f\u306e\u6a5f\u4f1a\u306b\u3054\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
\u4f8b\u5916\u5b89\u5168\u3078\u306e\u9053\u306f\u610f\u5916\u3068\u9577\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n
<\/p>\n","protected":false},"excerpt":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n
<\/p>\n
\u300c\u4f8b\u5916\u5b89\u5168 (Exception Safety)\u300d\u3068\u3044\u3046\u8a00\u8449\u3092\u3054\u5b58\u77e5\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n
<\/p>\n
\u9031\u672b\u3001\u672c\u306e\u6574\u7406\u3092\u3057\u3066\u3044\u305f\u3068\u304d\u306b\u300cExceptional C++\u300d\u3068\u3044\u3046\u672c\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[81,24,115],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3483"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=3483"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3483\/revisions"}],"predecessor-version":[{"id":17901,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3483\/revisions\/17901"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=3483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=3483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=3483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}