{"id":50571,"date":"2023-08-24T20:30:55","date_gmt":"2023-08-24T12:30:55","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=50571"},"modified":"2023-08-24T20:30:58","modified_gmt":"2023-08-24T12:30:58","slug":"java%e8%bf%90%e8%a1%8c%e6%97%b6%e5%bc%82%e5%b8%b8%e5%92%8c%e9%9d%9e%e8%bf%90%e8%a1%8c%e6%97%b6%e5%bc%82%e5%b8%b8%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/50571.html","title":{"rendered":"Java\u8fd0\u884c\u65f6\u5f02\u5e38\u548c\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\u7684\u533a\u522b\u662f\u4ec0\u4e48"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u5728Java\u7f16\u7a0b\u4e2d\uff0c\u5f02\u5e38\u53ef\u5206\u4e3a\u8fd0\u884c\u65f6\u5f02\u5e38\uff08RuntimeException\uff09\u548c\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\uff08Checked Exception\uff09\u3002<strong>1\u3001\u68c0\u67e5\u65f6\u673a<\/strong>\uff1b<strong>2\u3001\u5904\u7406\u8d23\u4efb<\/strong>\uff1a\u8fd0\u884c\u65f6\u5f02\u5e38\u4e0d\u5f3a\u5236\u8981\u6c42\u5904\u7406\uff0c\u800c\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\u5fc5\u987b\u663e\u5f0f\u5904\u7406\u6216\u629b\u51fa\uff1b<strong>3\u3001\u7ee7\u627f\u7ed3\u6784<\/strong>\uff1a\u8fd0\u884c\u65f6\u5f02\u5e38\u7ee7\u627f\u81ea<code>RuntimeException<\/code>\u7c7b\uff0c\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\u7ee7\u627f\u81ea<code>Exception<\/code>\u7c7b\u3002\u5728\u5904\u7406\u8d23\u4efb\u65b9\u9762\uff0c\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\u5f3a\u5236\u7a0b\u5e8f\u5458\u5728\u7f16\u7801\u9636\u6bb5\u5c31\u8981\u8003\u8651\u5230\u5f02\u5e38\u5904\u7406\uff0c\u4ece\u800c\u63d0\u9ad8\u4ee3\u7801\u7684\u5065\u58ee\u6027\u3002<\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"680\" height=\"421\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/08\/pingcode\u6b63\u6587-35-2.jpg?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-50573\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/08\/pingcode\u6b63\u6587-35-2.jpg 680w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/08\/pingcode\u6b63\u6587-35-2-300x186.jpg 300w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u68c0\u67e5\u65f6\u673a<\/strong><\/h2>\n\n\n\n<p>1\u3001<strong>\u8fd0\u884c\u65f6\u5f02\u5e38<\/strong>: \u8fd9\u7c7b\u5f02\u5e38\u901a\u5e38\u8868\u793a\u7f16\u7a0b\u9519\u8bef\uff0c\u5982\u9664\u6570\u4e3a\u96f6\u3001\u6570\u7ec4\u8d8a\u754c\u7b49\u3002\u8fd9\u7c7b\u5f02\u5e38\u662f\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u624d\u88ab\u68c0\u67e5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int result = 10 \/ 0; \/\/ \u629b\u51faArithmeticException\uff0c\u662f\u4e00\u79cd\u8fd0\u884c\u65f6\u5f02\u5e38\r<\/code><\/pre>\n\n\n\n<p><strong>2\u3001\u975e\u8fd0\u884c\u65f6\u5f02\u5e38<\/strong>: \u8fd9\u7c7b\u5f02\u5e38\u901a\u5e38\u8868\u793a\u53ef\u9884\u89c1\u7684\u9519\u8bef\u6761\u4ef6\uff0c\u5982\u6587\u4ef6\u4e0d\u5b58\u5728\u3001\u7f51\u7edc\u95ee\u9898\u7b49\u3002\u8fd9\u7c7b\u5f02\u5e38\u5728\u7f16\u8bd1\u9636\u6bb5\u5c31\u9700\u8981\u5904\u7406\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FileReader reader = new FileReader(\"nonexistent-file.txt\"); \/\/ \u629b\u51faFileNotFoundException\uff0c\u662f\u4e00\u79cd\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u5904\u7406\u8d23\u4efb<\/strong><\/h2>\n\n\n\n<ol>\n<li><strong>\u8fd0\u884c\u65f6\u5f02\u5e38<\/strong>: \u7f16\u8bd1\u5668\u4e0d\u4f1a\u68c0\u67e5\u662f\u5426\u6709\u5904\u7406\u6216\u629b\u51fa\u8fd0\u884c\u65f6\u5f02\u5e38\uff0c\u5b8c\u5168\u4f9d\u8d56\u4e8e\u7a0b\u5e8f\u5458\u3002<\/li>\n\n\n\n<li><strong>\u975e\u8fd0\u884c\u65f6\u5f02\u5e38<\/strong>: \u7f16\u8bd1\u5668\u4f1a\u5f3a\u5236\u8981\u6c42\u5bf9\u8fd9\u7c7b\u5f02\u5e38\u8fdb\u884c\u5904\u7406\uff08try-catch\uff09\u6216\u8005\u58f0\u660e\u629b\u51fa\uff08throws\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u7ee7\u627f\u7ed3\u6784<\/strong><\/h2>\n\n\n\n<ol>\n<li><strong>\u8fd0\u884c\u65f6\u5f02\u5e38<\/strong>: \u7ee7\u627f\u81ea<code>RuntimeException<\/code>\u7c7b\u3002<\/li>\n\n\n\n<li><strong>\u975e\u8fd0\u884c\u65f6\u5f02\u5e38<\/strong>: \u7ee7\u627f\u81ea<code>Exception<\/code>\u7c7b\uff0c\u4f46\u4e0d\u5305\u62ec<code>RuntimeException<\/code>\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\" \/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5e38\u89c1\u95ee\u7b54<\/strong><\/h2>\n\n\n\n<ul>\n<li><strong>Q1: \u662f\u5426\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\u4f7f\u7528\u8fd0\u884c\u65f6\u5f02\u5e38\uff1f<\/strong><\/li>\n\n\n\n<li>\u4e0d\u4e00\u5b9a\u3002\u8fd0\u884c\u65f6\u5f02\u5e38\u7528\u4e8e\u6807\u8bb0\u7a0b\u5e8f\u5458\u7684\u7f16\u7a0b\u9519\u8bef\uff0c\u4e00\u822c\u4e0d\u5e94\u88ab\u6355\u83b7\uff0c\u9664\u975e\u4f60\u6709\u7279\u6b8a\u7684\u4fee\u590d\u903b\u8f91\u3002<\/li>\n\n\n\n<li><strong>Q2: \u5982\u4f55\u81ea\u5b9a\u4e49\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\uff1f<\/strong><\/li>\n\n\n\n<li>\u53ef\u4ee5\u901a\u8fc7\u7ee7\u627f<code>Exception<\/code>\u7c7b\uff0c\u5e76\u5b9e\u73b0\u6784\u9020\u65b9\u6cd5\u6765\u81ea\u5b9a\u4e49\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\u3002<\/li>\n\n\n\n<li><strong>Q3: \u5728\u63a5\u53e3\u4e2d\u5e94\u8be5\u58f0\u660e\u8fd0\u884c\u65f6\u5f02\u5e38\u5417\uff1f<\/strong><\/li>\n\n\n\n<li>\u4e00\u822c\u4e0d\u5efa\u8bae\u5728\u63a5\u53e3\u4e2d\u58f0\u660e\u8fd0\u884c\u65f6\u5f02\u5e38\uff0c\u56e0\u4e3a\u5b83\u4eec\u901a\u5e38\u662f\u5b9e\u73b0\u7ec6\u8282\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u5728Java\u7f16\u7a0b\u4e2d\uff0c\u5f02\u5e38\u53ef\u5206\u4e3a\u8fd0\u884c\u65f6\u5f02\u5e38\uff08RuntimeException\uff09\u548c\u975e\u8fd0\u884c\u65f6\u5f02\u5e38\uff08Checked Ex [&hellip;]","protected":false},"author":6,"featured_media":50572,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[1964,1965,1966,367],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/50571"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=50571"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/50571\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/50572"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=50571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=50571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=50571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}