{"id":4171,"date":"2019-03-24T15:12:14","date_gmt":"2019-03-24T06:12:14","guid":{"rendered":"https:\/\/www.wsmeguro.jp\/wp\/?p=4171"},"modified":"2019-05-24T20:50:24","modified_gmt":"2019-05-24T11:50:24","slug":"dart%e3%81%ae%e5%8b%89%e5%bc%b7%ef%bc%99%ef%bc%9a%e4%be%8b%e5%a4%96%e5%87%a6%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.wsmeguro.jp\/wp\/?p=4171","title":{"rendered":"Dart\u306e\u52c9\u5f37\uff19\uff1a\u4f8b\u5916\u51e6\u7406"},"content":{"rendered":"<p>Dart\u306e<a href=\"https:\/\/api.dartlang.org\/stable\/2.2.0\/dart-core\/Exception-class.html\" target=\"_blank\" rel=\"noopener noreferrer\">HP<\/a>\u3067\u306f\u3001\u7528\u610f\u3055\u308c\u3066\u3044\u308bException\u306f\uff16\u3064\u3042\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n\u2460DeferredLoadException<br \/>\n\u2461FormatException<br \/>\n\u2462IntegerDivisionByZeroException<br \/>\n\u2463IOException<br \/>\n\u2464IsolateSpawnException<br \/>\n\u2465TimeoutException<\/p>\n<pre class=\"lang:java decode:true \">void main() {\r\n  int a =5;\r\n  int b=0;\r\n  int c=a~\/b;\r\n  print(\"The result is $c.\");\r\n}\r\n<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002\u592a\u5b57\u306e\u3068\u3053\u308d\u306b\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u304c\u51fa\u3066\u3044\u307e\u3059\u3002<br \/>\nUnhandled exception:<br \/>\n<strong>IntegerDivisionByZeroException<\/strong><br \/>\n#0 int.~\/ (dart:core\/runtime\/libintegers.dart:18:7)<br \/>\n#1 main (file:\/\/\/D:\/MySource\/dart\/test\/test3.dart:5:10)<br \/>\n#2 _startIsolate. (dart:isolate\/runtime\/libisolate_patch.dart:300:19)<br \/>\n#3 _RawReceivePortImpl._handleMessage (dart:isolate\/runtime\/libisolate_patch.dart:171:12)<!--more--><\/p>\n<p>\u306a\u306e\u3067\u3001\u30a8\u30e9\u30fc\u306e\u969b\u306bException\u304c\u6295\u3052\u3089\u308c\u308b\uff08throw\uff09\u306e\u3067\u3001\u3053\u308c\u3092catch\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u6b62\u307e\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u554f\u984c\u3068\u306a\u308a\u305d\u3046\u306a\u52d5\u4f5c\u3092\u958b\u59cb\u3059\u308b\u524d\u306btry\u3092\u5165\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:java decode:true \" >void main() {\r\n  int a = 5;\r\n  int b = 0;\r\n  \/\/\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u304c\u5206\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u300con\u300d\u3092\u4f7f\u3063\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u6b62\u3081\u305a\u306b\u51e6\u7406\u3092\u5f15\u304d\u7d99\u304e\u307e\u3059\u3002\r\n  print(\"CASE 1\");\r\n  try {\r\n    int c = a ~\/ b;\r\n    print(\"The result is $c.\");\r\n  } on IntegerDivisionByZeroException {\r\n    print(\"Don't devide by Zero!\");\r\n  }\r\n\r\n  \/\/\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u304c\u5206\u304b\u3063\u3066\u306a\u3044\u5834\u5408\u306f\u300ccatch\u300d\u3092\u4f7f\u3063\u3066\u3001\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u3092\u53d6\u5f97\u3057\u8868\u793a\u3002\r\n  print(\"\\nCASE 2\");\r\n  try {\r\n    int c = a ~\/ b;\r\n    print(\"The result is $c.\");\r\n  } catch (e) {\r\n    print(\"The exception thrown is $e\");\r\n  }\r\n\r\n  \/\/\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u304c\u5206\u304b\u3063\u3066\u306a\u3044\u5834\u5408\u306f\u300ccatch\u300d\u3092\u4f7f\u3063\u3066\u3001\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u3092\u53d6\u5f97\u3057\u8868\u793a\u3057\u3001\u307e\u305f\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3082\u8868\u793a\r\n  print(\"\\nCASE 3\");\r\n  try {\r\n    int c = a ~\/ b;\r\n    print(\"The result is $c.\");\r\n  } catch (e, s) {\r\n    print(\"The exception thrown is $e\");\r\n    print(\"STACK TRACE\\n $s\");\r\n  }\r\n\r\n  \/\/\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u304c\u5206\u304b\u3063\u3066\u306a\u3044\u5834\u5408\u306f\u300ccatch\u300d\u3092\u4f7f\u3063\u3066\u3001\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u3092\u53d6\u5f97\u3057\u8868\u793a\u3057\u3001\u307e\u305f\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3082\u8868\u793a\r\n  print(\"\\nCASE 4\");\r\n  try {\r\n    int c = a ~\/ b;\r\n    print(\"The result is $c.\");\r\n  } catch (e) {\r\n    print(\"The exception thrown is $e\");\r\n  } finally {\r\n    print(\"Finally Clause is always executed.\");\r\n  }\r\n\r\n  \/\/\u30ab\u30b9\u30bf\u30e0\u4f8b\u5916\u51e6\u7406\r\n  print(\"\\nCASE 5\");\r\n  try {\r\n    inputValue(-20);\r\n  }catch(e){\r\n    print(e.errorMessage());\r\n  }\r\n}\r\n\r\nclass InputValueException implements Exception {\r\n  String errorMessage() {\r\n    return \"You cannot enter a number less than 0.\";\r\n  }\r\n}\r\n\r\nvoid inputValue(int size) {\r\n  if (size &lt; 0) {\r\n    throw new InputValueException();\r\n  } else {\r\n    print(\"The size is $size.\");\r\n  }\r\n}\r\n<\/pre>\n<p>\u3061\u3087\u3063\u3068\u9577\u3044\u3067\u3059\u304c\u3001try\u30b7\u30ea\u30fc\u30ba\u3092\u3066\u3093\u3053\u76db\u308a\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\n\u6700\u521d\u304b\u3089\u4f8b\u5916\u306e\u30bf\u30a4\u30d7\u304c\u5206\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u300con\u300d\u3067\u5f15\u304d\u7d99\u304e\u3001\u5206\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u300ccatch(e,s)\u300d\u3067\u4f8b\u5916\u30bf\u30a4\u30d7\u3084\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d6\u5f97\u3057\u3066\u304b\u3089\u6b21\u3092\u8003\u3048\u308b\u3002\u300cfinally\u300d\u7d76\u5bfe\u3084\u3063\u3066\u304a\u304d\u305f\u3044\u51e6\u7406\u3092\u5165\u308c\u3066\u304a\u304f\u5834\u6240\u3067\u3001\u81ea\u5206\u3067\u30a8\u30e9\u30fc\u3092\u8a2d\u5b9a\u3057\u305f\u3044\u3068\u304d\u306f\u30af\u30e9\u30b9\u3092\u4f5c\u308b\u3002\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u3002\u51e6\u7406\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<br \/>\nCASE 1<br \/>\nDon&#8217;t devide by Zero!<\/p>\n<p>CASE 2<br \/>\nThe exception thrown is IntegerDivisionByZeroException<\/p>\n<p>CASE 3<br \/>\nThe exception thrown is IntegerDivisionByZeroException<br \/>\nSTACK TRACE<br \/>\n #0      int.~\/ (dart:core\/runtime\/libintegers.dart:18:7)<br \/>\n#1      main (file:\/\/\/D:\/MySource\/dart\/test\/test3.dart:25:15)<br \/>\n#2      _startIsolate.<anonymous closure> (dart:isolate\/runtime\/libisolate_patch.dart:300:19)<br \/>\n#3      _RawReceivePortImpl._handleMessage (dart:isolate\/runtime\/libisolate_patch.dart:171:12)<\/p>\n<p>CASE 4<br \/>\nThe exception thrown is IntegerDivisionByZeroException<br \/>\nFinally Clause is always executed.<\/p>\n<p>CASE 5<br \/>\nYou cannot enter a number less than 0.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dart\u306eHP\u3067\u306f\u3001\u7528\u610f\u3055\u308c\u3066\u3044\u308bException\u306f\uff16\u3064\u3042\u308b\u3088\u3046\u3067\u3059\u3002 \u2460DeferredLoadException \u2461FormatException \u2462IntegerDivisionByZeroException \u2463&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[595,505],"tags":[636,635,639,638,637,634],"class_list":["post-4171","post","type-post","status-publish","format-standard","hentry","category-dart2","category-programming","tag-catch","tag-custom-exception","tag-finally","tag-on","tag-try","tag-634"],"_links":{"self":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4171"}],"version-history":[{"count":5,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4171\/revisions"}],"predecessor-version":[{"id":4215,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4171\/revisions\/4215"}],"wp:attachment":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}