\u6355\u83b7\u5f02\u5e38<\/strong><\/div>\n\u5f02\u5e38\u6355\u6349\u7684\u673a\u5236\u4e0e\u5176\u4ed6\u8bed\u8a00\u4e2d\u4e00\u6837\uff0c\u5982\u679c\u6709\u5f02\u5e38\u53d1\u751f\uff0ccatch\u5b57\u53e5\u662f\u6309\u6b21\u5e8f\u6355\u6349\u7684\u3002\u56e0\u6b64\uff0c\u5728catch\u5b57\u53e5\u4e2d\uff0c\u8d8a\u5177\u4f53\u7684\u5f02\u5e38\u8d8a\u8981\u9760\u524d\uff0c\u8d8a\u666e\u904d\u7684\u5f02\u5e38\u8d8a\u9760\u540e\u3002 \u5982\u679c\u629b\u51fa\u7684\u5f02\u5e38\u4e0d\u5728catch\u5b57\u53e5\u4e2d\uff0c\u8be5\u5f02\u5e38\u5219\u65e0\u6cd5\u5904\u7406\uff0c\u4f1a\u88ab\u5347\u7ea7\u5230\u8c03\u7528\u8005\u5904\u3002<\/p>\n
\u6355\u6349\u5f02\u5e38\u7684catch\u5b50\u53e5\uff0c\u8bed\u6cd5\u4e0e\u5176\u4ed6\u8bed\u8a00\u4e2d\u4e0d\u592a\u4e00\u6837\u3002\u5728Scala\u91cc\uff0c\u501f\u7528\u4e86\u6a21\u5f0f\u5339\u914d\u7684\u601d\u60f3\u6765\u505a\u5f02\u5e38\u7684\u5339\u914d\uff0c\u56e0\u6b64\uff0c\u5728catch\u7684\u4ee3\u7801\u91cc\uff0c\u662f\u4e00\u7cfb\u5217case\u5b57\u53e5\uff0c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a<\/p>\n
\r\nimport java.io.FileReader\r\nimport java.io.FileNotFoundException\r\nimport java.io.IOException\r\n\r\nobject Test {\r\n def main(args: Array[String]) {\r\n try {\r\n val f = new FileReader(\"input.txt\")\r\n } catch {\r\n case ex: FileNotFoundException =>{\r\n println(\"Missing file exception\")\r\n }\r\n case ex: IOException => {\r\n println(\"IO Exception\")\r\n }\r\n }\r\n }\r\n}<\/pre>\n\u6267\u884c\u4ee5\u4e0a\u4ee3\u7801\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n
\r\n$ scalac Test.scala \r\n$ scala Test\r\nMissing file exception<\/pre>\ncatch\u5b57\u53e5\u91cc\u7684\u5185\u5bb9\u8ddfmatch\u91cc\u7684case\u662f\u5b8c\u5168\u4e00\u6837\u7684\u3002\u7531\u4e8e\u5f02\u5e38\u6355\u6349\u662f\u6309\u6b21\u5e8f\uff0c\u5982\u679c\u6700\u666e\u904d\u7684\u5f02\u5e38\uff0cThrowable\uff0c\u5199\u5728\u6700\u524d\u9762\uff0c\u5219\u5728\u5b83\u540e\u9762\u7684case\u90fd\u6355\u6349\u4e0d\u5230\uff0c\u56e0\u6b64\u9700\u8981\u5c06\u5b83\u5199\u5728\u6700\u540e\u9762\u3002<\/p>\n
finally \u8bed\u53e5<\/strong><\/div>\nfinally \u8bed\u53e5\u7528\u4e8e\u6267\u884c\u4e0d\u7ba1\u662f\u6b63\u5e38\u5904\u7406\u8fd8\u662f\u6709\u5f02\u5e38\u53d1\u751f\u65f6\u90fd\u9700\u8981\u6267\u884c\u7684\u6b65\u9aa4\uff0c\u5b9e\u4f8b\u5982\u4e0b\uff1a<\/p>\n
\r\nimport java.io.FileReader\r\nimport java.io.FileNotFoundException\r\nimport java.io.IOException\r\n\r\nobject Test {\r\n def main(args: Array[String]) {\r\n try {\r\n val f = new FileReader(\"input.txt\")\r\n } catch {\r\n case ex: FileNotFoundException => {\r\n println(\"Missing file exception\")\r\n }\r\n case ex: IOException => {\r\n println(\"IO Exception\")\r\n }\r\n } finally {\r\n println(\"Exiting finally...\")\r\n }\r\n }\r\n}<\/pre>\n\u6267\u884c\u4ee5\u4e0a\u4ee3\u7801\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n
\r\n$ scalac Test.scala \r\n$ scala Test\r\nMissing file exception\r\nExiting finally...<\/pre>\n","protected":false},"excerpt":{"rendered":"Scala \u7684\u5f02\u5e38\u5904\u7406\u548c\u5176\u5b83\u8bed\u8a00\u6bd4\u5982 Java \u7c7b\u4f3c\u3002 Scala \u7684\u65b9\u6cd5\u53ef\u4ee5\u901a\u8fc7\u629b\u51fa\u5f02\u5e38\u7684\u65b9\u6cd5\u7684\u65b9\u5f0f\u6765\u7ec8\u6b62\u76f8 […]<\/p>\n","protected":false},"author":1470,"featured_media":201759,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-201771","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=201771"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201771\/revisions"}],"predecessor-version":[{"id":201776,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201771\/revisions\/201776"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/201759"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=201771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=201771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=201771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}