{"id":53661,"date":"2025-08-12T14:49:53","date_gmt":"2025-08-12T06:49:53","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/53661.html"},"modified":"2025-08-12T14:49:53","modified_gmt":"2025-08-12T06:49:53","slug":"%e4%bc%98%e9%9b%85%e5%a4%84%e7%90%86%e5%bc%82%e5%b8%b8%ef%bc%9ajava%e7%a8%8b%e5%ba%8f%e5%91%98%e5%bf%85%e5%a4%87%e6%8a%80%e8%83%bd","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/53661.html","title":{"rendered":"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd"},"content":{"rendered":"<h2 style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812064947-689ae40bb9f3c.png\" \/><\/h2>\n<h2>\u58f9\u3001\u5f15\u8a00\u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728\u6570\u5b57\u5316\u751f\u5b58\u65f6\u4ee3&#xff0c;\u5f02\u5e38\u5904\u7406\u5982\u540c\u7a0b\u5e8f\u4e16\u754c\u7684\u514d\u75ab\u7cfb\u7edf\u3002\u5f02\u5e38\u5904\u7406\u7684\u4e09\u4e2a\u6838\u5fc3\u7ef4\u5ea6\u2014\u2014\u9632\u5fa1\u6027\u7f16\u7a0b\u3001\u5951\u7ea6\u5f0f\u8bbe\u8ba1\u548c\u5f39\u6027\u67b6\u6784&#xff0c;\u5206\u522b\u4ece\u4ee3\u7801\u7ea7\u9632\u62a4\u3001\u89c4\u8303\u7ea6\u675f\u548c\u7cfb\u7edf\u7ea7\u5bb9\u9519\u4e09\u4e2a\u5c42\u9762\u6784\u5efa\u5b8c\u6574\u7684\u5f02\u5e38\u5904\u7406\u4f53\u7cfb\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"512\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812064949-689ae40d82734.png\" width=\"339\" \/><\/p>\n<hr \/>\n<h2>\u8d30\u3001\u5f02\u5e38\u5f15\u5165<\/h2>\n<p><span style=\"color:#262626\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5f02\u5e38&#xff08; Exception <\/span><span style=\"color:#262626\">&#xff09;\u5c31\u662f\u5728\u7a0b\u5e8f\u7684\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u6240\u53d1\u751f\u7684\u4e0d\u6b63\u5e38\u7684\u4e8b\u4ef6&#xff0c;\u5b83\u4f1a\u4e2d \u65ad\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002<\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u6240\u9700\u6587\u4ef6\u627e\u4e0d\u5230 <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u7f51\u7edc\u8fde\u63a5\u4e0d\u901a\u6216\u4e2d\u65ad <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u7b97\u672f\u8fd0\u7b97\u9519 <\/span><span style=\"color:#262626\">(<\/span><span style=\"color:#262626\">\u88ab\u96f6\u9664<\/span><span style=\"color:#262626\">\u2026) <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u6570\u7ec4\u4e0b\u6807\u8d8a\u754c <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u88c5\u8f7d\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u7c7b\u6216\u8005\u5bf9<\/span><span style=\"color:#262626\">null<\/span><span style=\"color:#262626\">\u5bf9\u8c61\u64cd\u4f5c <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u7c7b\u578b\u8f6c\u6362\u5f02\u5e38 <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u2026\u2026 <\/span><\/p>\n<p><span style=\"color:#262626\">\u5f53<\/span><span style=\"color:#262626\">Java<\/span><span style=\"color:#262626\">\u7a0b\u5e8f\u51fa\u73b0\u4ee5\u4e0a\u7684\u5f02\u5e38\u65f6&#xff0c;\u5c31\u4f1a\u5728\u6240\u5904\u7684\u65b9\u6cd5\u4e2d\u4ea7\u751f\u4e00\u4e2a\u5f02\u5e38\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5f02\u5e38\u5bf9\u8c61 \u5305\u62ec\u5f02\u5e38\u7684\u7c7b\u578b&#xff0c;\u5f02\u5e38\u51fa\u73b0\u65f6\u7a0b\u5e8f\u7684\u8fd0\u884c\u72b6\u6001\u4ee5\u53ca\u5bf9\u8be5\u5f02\u5e38\u7684\u8be6\u7ec6\u63cf\u8ff0\u3002<\/span><\/p>\n<p><span style=\"color:#262626\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7a0b\u5e8f\u4e2d\u7684\u5f02\u5e38\u793a\u4f8b<\/span><span style=\"color:#262626\">&#xff1a;\u7ed9\u51fa\u9664\u6570\u548c\u88ab\u9664\u6570&#xff0c;\u6c42\u5546\u3002<\/span><\/p>\n<p>  <span style=\"color:#262626\">\u2022 <\/span><br \/>\n  <span style=\"color:#262626\">\u5982\u679c\u9664\u6570\u4e3a<\/span><br \/>\n  <span style=\"color:#262626\">0<\/span><br \/>\n  <span style=\"color:#262626\">&#xff0c;\u51fa\u73b0\u5f02\u5e38 <\/span><\/p>\n<p>  <span style=\"color:#262626\">\u2022 <\/span><br \/>\n  <span style=\"color:#262626\">\u5982\u679c\u9664\u6570\u6216\u8005\u88ab\u9664\u6570\u4e0d\u662f\u6570\u5b57&#xff0c;\u51fa\u73b0\u5f02\u5e38<\/span><\/p>\n<ul><\/ul>\n<p><span style=\"color:#262626\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u9762\u5bf9\u5f02\u5e38\u8be5\u600e\u4e48\u529e\u5462&#xff1f; <\/span><\/p>\n<p><span style=\"color:#262626\">\u65b9\u5f0f<\/span><span style=\"color:#262626\">1<\/span><span style=\"color:#262626\">&#xff1a;\u7531\u5f00\u53d1\u8005\u901a\u8fc7<\/span><span style=\"color:#262626\">if-else<\/span><span style=\"color:#262626\">\u6765\u89e3\u51b3\u5f02\u5e38\u95ee\u9898 <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u4ee3\u7801\u81c3\u80bf&#xff1a;\u4e1a\u52a1\u4ee3\u7801\u548c\u5f02\u5e38\u5904\u7406\u4ee3\u7801\u653e\u4e00\u8d77 <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u7a0b\u5e8f\u5458\u8981\u82b1\u5f88\u5927\u7cbe\u529b<\/span><span style=\"color:#262626\">&#034;<\/span><span style=\"color:#262626\">\u5835\u6f0f\u6d1e\u201c <\/span><\/p>\n<p><span style=\"color:#262626\">\u2022 <\/span><span style=\"color:#262626\">\u7a0b\u5e8f\u5458\u5f88\u96be\u5835\u4f4f\u6240\u6709\u201c\u6f0f\u6d1e\u201d&#xff0c;\u5bf9\u7a0b\u5e8f\u5458\u672c\u8eab\u8981\u6c42\u8f83\u9ad8 <\/span><\/p>\n<p><span style=\"color:#262626\">\u65b9\u5f0f<\/span><span style=\"color:#262626\">2<\/span><span style=\"color:#262626\">&#xff1a;\u5f00\u53d1\u8005\u4e0d\u9700\u8981\u901a\u8fc7<\/span><span style=\"color:#262626\">if-else<\/span><span style=\"color:#262626\">\u6765\u89e3\u51b3\u5f02\u5e38\u95ee\u9898&#xff0c;\u800c\u662f<\/span><span style=\"color:#262626\">Java<\/span><span style=\"color:#262626\">\u63d0\u4f9b\u5f02\u5e38\u5904\u7406\u673a\u5236\u3002\u5b83\u5c06\u5f02\u5e38\u5904\u7406\u4ee3 <\/span><\/p>\n<p><span style=\"color:#262626\">\u7801\u548c\u548c\u4e1a\u52a1\u4ee3\u7801\u5206\u79bb&#xff0c;\u4f7f\u7a0b\u5e8f\u66f4\u4f18\u96c5&#xff0c;\u66f4\u597d\u7684\u5bb9\u9519\u6027&#xff0c;\u9ad8\u952e\u58ee\u6027\u3002<\/span><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"267\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812064950-689ae40e1cb3b.png\" width=\"1398\" \/><\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Java\u5f02\u5e38\u673a\u5236\u662f\u5904\u7406\u7a0b\u5e8f\u8fd0\u884c\u65f6\u9519\u8bef\u7684\u4e00\u79cd\u7ed3\u6784\u5316\u65b9\u5f0f\u3002\u5f53\u7a0b\u5e8f\u51fa\u73b0\u610f\u5916\u60c5\u51b5\u65f6&#xff0c;\u4f1a&#034;\u629b\u51fa&#034;\u5f02\u5e38\u5bf9\u8c61&#xff0c;\u7a0b\u5e8f\u53ef\u4ee5&#034;\u6355\u83b7&#034;\u5e76\u5904\u7406\u8fd9\u4e9b\u5f02\u5e38&#xff0c;\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<p>\/\/\u00a0\u00a0\u7a0b\u5e8f\u4e2d\u7684\u5f02\u5e38\u793a\u4f8b&#xff1a;\u7ed9\u51fa\u9664\u6570\u548c\u88ab\u9664\u6570&#xff0c;\u6c42\u5546\u3002<br \/>\n\/**<br \/>\n *\u6570\u5b66\u539f\u7406\u8bf4\u660e&#xff1a;<br \/>\n *\u5f53\u88ab\u9664\u6570\u4e3a0\u4e14\u9664\u6570\u975e\u96f6\u65f6&#xff0c;\u5546\u5fc5\u7136\u4e3a0<br \/>\n *\u9664\u6570\u4e3a0\u7684\u60c5\u51b5\u5728\u6570\u5b66\u4e0a\u65e0\u5b9a\u4e49&#xff0c;\u5fc5\u987b\u629b\u51fa\u5f02\u5e38<br \/>\n *\u975e\u6570\u5b57\u8f93\u5165\u4f1a\u5bfc\u81f4\u89e3\u6790\u5931\u8d25&#xff0c;\u5c5e\u4e8e\u975e\u6cd5\u64cd\u4f5c<br \/>\n *<br \/>\n *\/<\/p>\n<p>import java.util.InputMismatchException;<br \/>\nimport java.util.Scanner;<\/p>\n<p>public class DivisionCalculator {<br \/>\n    public static void main(String[] args) {<br \/>\n        Scanner scanner &#061; new Scanner(System.in);<\/p>\n<p>        try {<br \/>\n            System.out.print(&#034;\u8bf7\u8f93\u5165\u88ab\u9664\u6570: &#034;);<br \/>\n            double dividend &#061; scanner.nextDouble();<\/p>\n<p>            System.out.print(&#034;\u8bf7\u8f93\u5165\u9664\u6570: &#034;);<br \/>\n            double divisor &#061; scanner.nextDouble();<\/p>\n<p>            if (divisor &#061;&#061; 0) {<br \/>\n                throw new ArithmeticException(&#034;\u9664\u6570\u4e0d\u80fd\u4e3a0&#034;);<br \/>\n            }<\/p>\n<p>            double result &#061; dividend \/ divisor;<br \/>\n            System.out.println(&#034;\u8ba1\u7b97\u7ed3\u679c: &#034; &#043; dividend &#043; &#034; \/ &#034; &#043; divisor &#043; &#034; &#061; &#034; &#043; result);<\/p>\n<p>        } catch (InputMismatchException e) {<br \/>\n            System.err.println(&#034;\u9519\u8bef: \u8f93\u5165\u5fc5\u987b\u662f\u6570\u5b57&#034;);<br \/>\n        } catch (ArithmeticException e) {<br \/>\n            System.err.println(&#034;\u9519\u8bef: &#034; &#043; e.getMessage());<br \/>\n        } finally {<br \/>\n            scanner.close();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<hr \/>\n<h2>\u53c1\u3001\u5f02\u5e38\u5206\u7c7b<\/h2>\n<table>\n<tr>\u7c7b\u578b\u200c\u200c\u7279\u70b9\u200c\u200c\u5e38\u89c1\u5b50\u7c7b\u4e3e\u4f8b\u200c<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:center\">\u200cError\u200c<\/td>\n<td style=\"text-align:center\">JVM\u7cfb\u7edf\u7ea7\u9519\u8bef&#xff0c;\u7a0b\u5e8f\u65e0\u6cd5\u5904\u7406&#xff0c;\u901a\u5e38\u5bfc\u81f4\u8fdb\u7a0b\u7ec8\u6b62<\/td>\n<td style=\"text-align:center\">OutOfMemoryError&#xff08;\u5185\u5b58\u6ea2\u51fa&#xff09; StackOverflowError&#xff08;\u6808\u6ea2\u51fa&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">\u200cException\u200c<\/td>\n<td style=\"text-align:center\">\u7a0b\u5e8f\u53ef\u5904\u7406\u7684\u5f02\u5e38<\/td>\n<td style=\"text-align:center\">\u5305\u542b\u68c0\u67e5\u5f02\u5e38\u548c\u975e\u68c0\u67e5\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">\u00a0\u00a0\u21b3 \u200cChecked Exception\u200c&#xff08;\u68c0\u67e5\u5f02\u5e38&#xff09;<\/td>\n<td style=\"text-align:center\">\u7f16\u8bd1\u65f6\u5f3a\u5236\u5904\u7406&#xff0c;\u9700\u663e\u5f0f\u6355\u83b7\u6216\u58f0\u660e\u629b\u51fa<\/td>\n<td style=\"text-align:center\">IOException SQLException ClassNotFoundException<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">\u00a0\u00a0\u21b3 \u200cUnchecked Exception\u200c&#xff08;\u975e\u68c0\u67e5\u5f02\u5e38&#xff09;<\/td>\n<td style=\"text-align:center\">\u8fd0\u884c\u65f6\u5f02\u5e38&#xff0c;\u7f16\u8bd1\u5668\u4e0d\u5f3a\u5236\u5904\u7406<\/td>\n<td style=\"text-align:center\">NullPointerException ArithmeticException ArrayIndexOutOfBoundsException<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Java\u5f02\u5e38\u5206\u4e3a\u4e24\u5927\u7c7b&#xff1a;<\/p>\n<h3>\u4e00\u3001Error\u200c&#xff1a;\u7cfb\u7edf\u7ea7\u9519\u8bef&#xff0c;\u7a0b\u5e8f\u901a\u5e38\u65e0\u6cd5\u5904\u7406&#xff08;OutOfMemoryError&#xff09;<\/h3>\n<p><span style=\"color:#262626\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Error\u7c7b\u5c42\u6b21\u63cf\u8ff0\u4e86<\/span><span style=\"color:#262626\">Java<\/span><span style=\"color:#262626\">\u8fd0\u884c\u65f6\u7cfb\u7edf\u5185\u90e8\u9519\u8bef\u548c\u8d44\u6e90\u8017\u5c3d\u9519\u8bef&#xff0c;\u4e00\u822c\u6307\u4e0eJVM\u6216\u52a8\u6001\u52a0\u8f7d\u7b49\u76f8\u5173\u7684\u95ee\u9898&#xff0c;\u5982\u865a\u62df\u673a\u9519\u8bef&#xff0c;\u52a8\u6001\u94fe\u63a5\u5931\u8d25&#xff0c;\u7cfb\u7edf\u5d29\u6e83\u7b49\u3002 \u8fd9\u7c7b\u9519\u8bef\u662f\u6211\u4eec\u65e0\u6cd5\u63a7\u5236\u7684&#xff0c;\u540c\u65f6\u4e5f\u662f\u975e\u5e38\u7f55\u89c1\u7684\u9519\u8bef\u3002\u6240\u4ee5\u5728\u7f16\u7a0b\u4e2d&#xff0c;\u4e0d\u53bb\u5904\u7406\u8fd9\u7c7b\u9519\u8bef\u3002 <\/span><\/p>\n<p><span style=\"color:#262626\">\u00a0<\/span><span style=\"color:#262626\">\u6ce8&#xff1a;\u6211\u4eec\u4e0d\u9700\u8981\u7ba1\u7406<\/span><span style=\"color:#262626\">Error&#xff01;&#xff08;\u53ef\u4ee5\u6253\u5f00JDK\u5305&#xff1a;<\/span><span style=\"color:#262626\">java.lang.Error<\/span><span style=\"color:#262626\">&#xff0c;\u67e5\u770b\u4ed6\u7684\u6240\u6709\u5b50\u7c7b&#xff09;<\/span><\/p>\n<h3>\u4e8c\u3001Exception\u200c&#xff1a;\u7a0b\u5e8f\u53ef\u4ee5\u5904\u7406\u7684\u5f02\u5e38<\/h3>\n<p>Exception\u200c\u53c8\u5206\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\u200cChecked Exception\u200c&#xff08;\u7f16\u8bd1\u65f6\u5f02\u5e38&#xff09;&#xff1a;\u5fc5\u987b\u5904\u7406&#xff08;\u5982IOException&#xff09;\u3002<\/li>\n<li>Unchecked Exception\u200c&#xff08;\u8fd0\u884c\u65f6\u5f02\u5e38&#xff09;&#xff1a;RuntimeException\u53ca\u5176\u5b50\u7c7b&#xff08;\u5982NullPointerException&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7f16\u8bd1\u65f6\u5f02\u5e38\u5728\u7f16\u8bd1\u65f6\u5c31\u4f1a\u88ab\u68c0\u6d4b\u5230&#xff0c;\u5fc5\u987b\u8fdb\u884c\u5904\u7406&#xff0c;\u5426\u5219\u65e0\u6cd5\u901a\u8fc7\u7f16\u8bd1&#xff1b;\u800c\u8fd0\u884c\u65f6\u5f02\u5e38&#xff08;\u5982RuntimeException&#xff09;\u901a\u5e38\u7531\u7a0b\u5e8f\u903b\u8f91\u9519\u8bef\u5f15\u8d77&#xff0c;\u4e0d\u5f3a\u5236\u5904\u7406\u3002<\/p>\n<h4><span style=\"color:#ff9900\">\u5f02\u5e38\u751f\u7269\u56fe\u9274<\/span><\/h4>\n<h5><span style=\"color:#ff9900\">1.1 Checked\u5f02\u5e38\u5bb6\u65cf&#xff08;\u5f3a\u8feb\u75c7\u578b&#xff09;<\/span><\/h5>\n<ul>\n<li>\n<p><span style=\"color:#ff9900\">IOException\u5bb6\u65cf &#034;\u6587\u4ef6\u627e\u4e0d\u5230&#xff1f;\u7f51\u7edc\u65ad\u8fde&#xff1f;\u8fd9\u4e00\u5b9a\u662f\u7384\u5b66\u95ee\u9898&#xff01;&#034; \u2014\u2014 \u6bcf\u4e2a\u7a0b\u5e8f\u5458\u90fd\u7ecf\u5386\u8fc7\u5bf9\u7740\u5b8c\u5168\u6b63\u786e\u7684\u8def\u5f84\u6000\u7591\u4eba\u751f\u7684\u65f6\u523b<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color:#ff9900\">SQLException\u4e09\u5144\u5f1f<\/span><\/p>\n<ul>\n<li>\n<p><span style=\"color:#ff9900\">\u5927\u54e5&#xff1a;\u4f60\u7684SQL\u8bed\u6cd5\u9519\u4e86&#xff08;\u5b9e\u9645\u662f\u5c11\u4e86\u5206\u53f7&#xff09;<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color:#ff9900\">\u4e8c\u54e5&#xff1a;\u8fde\u63a5\u8d85\u65f6&#xff08;DBA\u53c8\u5728\u91cd\u542f\u670d\u52a1&#xff09;<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color:#ff9900\">\u4e09\u5f1f&#xff1a;\u9501\u7b49\u5f85\u8d85\u65f6&#xff08;\u9694\u58c1\u7ec4\u53c8\u5728\u8dd1\u5168\u8868\u626b\u63cf&#xff09;<\/span><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5><span style=\"color:#ff9900\">1.2 Unchecked\u5f02\u5e38\u5929\u56e2&#xff08;\u523a\u5ba2\u578b&#xff09;<\/span><\/h5>\n<ul>\n<li>\n<p><span style=\"color:#ff9900\">NullPointerException &#034;\u5341\u5e74\u7f16\u7a0b\u4e24\u832b\u832b&#xff0c;NPE&#xff0c;\u81ea\u96be\u5fd8&#034; \u2014\u2014 Java\u5c4a\u7684\u5348\u591c\u51f6\u94c3&#xff0c;\u603b\u5728obj.method()\u65f6\u7a81\u7136\u95ea\u73b0<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color:#ff9900\">ClassCastException \u5f53\u4f60\u8bd5\u56fe\u628aArrayList\u5f53\u6210LinkedList\u7528\u65f6&#xff1a;&#034;\u4f60\u8bf4\u5f97\u5bf9&#xff0c;\u4f46\u662f\u300e\u7c7b\u578b\u8f6c\u6362\u300f\u662f\u7531Oracle\u81ea\u4e3b\u7814\u53d1\u7684\u5168\u65b0&#8230;&#034;<\/span><\/p>\n<\/li>\n<\/ul>\n<h3>\u4e09\u3001\u5e38\u89c1\u5f02\u5e38<\/h3>\n<\/p>\n<ul>\n<li>\n<p>\u200cNullPointerException&#xff08;\u7a7a\u6307\u9488\u5f02\u5e38&#xff09;\u200c<\/p>\n<ul>\n<li>\u200c\u89e6\u53d1\u573a\u666f\u200c&#xff1a;\u8c03\u7528null\u5bf9\u8c61\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\u3002<\/li>\n<li>\u200c\u793a\u4f8b\u200c&#xff1a;String str &#061; null; int len &#061; str.length();<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u200cArithmeticException&#xff08;\u7b97\u672f\u5f02\u5e38&#xff09;\u200c<\/p>\n<ul>\n<li>\u200c\u89e6\u53d1\u573a\u666f\u200c&#xff1a;\u9664\u6570\u4e3a\u96f6\u7684\u8fd0\u7b97\u3002<\/li>\n<li>\u200c\u793a\u4f8b\u200c&#xff1a;int a &#061; 5 \/ 0;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>public static int divide(int x, int y) {<br \/>\n    return x \/ y;  \/\/ \u82e5y&#061;0\u629b\u51faArithmeticException<br \/>\n}<\/p>\n<ul>\n<li>\n<p>\u200cArrayIndexOutOfBoundsException&#xff08;\u6570\u7ec4\u8d8a\u754c\u5f02\u5e38&#xff09;\u200c<\/p>\n<ul>\n<li>\u200c\u89e6\u53d1\u573a\u666f\u200c&#xff1a;\u8bbf\u95ee\u65e0\u6548\u6570\u7ec4\u7d22\u5f15\u3002<\/li>\n<li>\u200c\u793a\u4f8b\u200c&#xff1a;int[] arr &#061; new int[3]; int val &#061; arr[5];<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>try {<br \/>\n    int[] a &#061; {1, 2, 3};<br \/>\n    System.out.println(a[5]);  \/\/ \u7d22\u5f15\u8d8a\u754c<br \/>\n} catch (IndexOutOfBoundsException e) {<br \/>\n    System.out.println(&#034;\u9519\u8bef&#xff1a;&#034; &#043; e.getMessage());<br \/>\n}<\/p>\n<ul>\n<li>\n<p>\u200cClassCastException&#xff08;\u7c7b\u578b\u8f6c\u6362\u5f02\u5e38&#xff09;\u200c<\/p>\n<ul>\n<li>\u200c\u89e6\u53d1\u573a\u666f\u200c&#xff1a;\u5f3a\u5236\u8f6c\u6362\u4e0d\u517c\u5bb9\u7684\u5bf9\u8c61\u7c7b\u578b\u3002<\/li>\n<li>\u200c\u793a\u4f8b\u200c&#xff1a;Object obj &#061; &#034;text&#034;; Integer num &#061; (Integer) obj;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u200cNumberFormatException&#xff08;\u6570\u5b57\u683c\u5f0f\u5f02\u5e38&#xff09;\u200c<\/p>\n<ul>\n<li>\u200c\u89e6\u53d1\u573a\u666f\u200c&#xff1a;\u5b57\u7b26\u4e32\u8f6c\u6570\u503c\u65f6\u683c\u5f0f\u9519\u8bef\u3002<\/li>\n<li>\u200c\u793a\u4f8b\u200c&#xff1a;int num &#061; Integer.parseInt(&#034;abc&#034;);<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u200cIOException&#xff08;I\/O\u5f02\u5e38&#xff09;\u200c<\/p>\n<ul>\n<li>\u200c\u5b50\u7c7b\u200c&#xff1a;FileNotFoundException&#xff08;\u6587\u4ef6\u672a\u627e\u5230&#xff09; \u200c\u89e6\u53d1\u573a\u666f\u200c&#xff1a;\u6587\u4ef6\u8def\u5f84\u9519\u8bef\u6216\u6743\u9650\u4e0d\u8db3\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u200cInputMismatchException&#xff08;\u8f93\u5165\u4e0d\u5339\u914d\u5f02\u5e38&#xff09;\u200c<\/p>\n<ul>\n<li>\u200c\u89e6\u53d1\u573a\u666f\u200c&#xff1a;\u8f93\u5165\u6570\u636e\u7c7b\u578b\u4e0e\u9884\u671f\u4e0d\u7b26&#xff08;\u5982Scanner\u8bfb\u53d6\u975e\u6570\u5b57\u8f93\u5165&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>\u8086\u3001\u5f02\u5e38\u5904\u7406<\/h2>\n<p>\u5f02\u5e38\u5904\u7406\u5173\u952e\u5b57\u200c<\/p>\n<ul>\n<li>\u200ctry-catch-finally\u200c&#xff1a;\u6355\u83b7\u5f02\u5e38\u7684\u6838\u5fc3\u7ed3\u6784&#xff0c;finally\u5757\u4fdd\u8bc1\u8d44\u6e90\u91ca\u653e<\/li>\n<li>\u200cthrow\u200c&#xff1a;\u5728\u65b9\u6cd5\u5185\u90e8\u624b\u52a8\u629b\u51fa\u5f02\u5e38\u5bf9\u8c61<\/li>\n<li>\u200cthrows\u200c&#xff1a;\u58f0\u660e\u65b9\u6cd5\u53ef\u80fd\u629b\u51fa\u7684\u5f02\u5e38\u7c7b\u578b&#xff0c;\u7531\u8c03\u7528\u8005\u5904\u7406<\/li>\n<\/ul>\n<h4>\u5f02\u5e38\u5904\u7406\u6bb5\u4f4d\u6392\u884c<\/h4>\n<table>\n<tbody>\n<tr>\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u6bb5\u4f4d<\/span><\/p>\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u884c\u4e3a\u7279\u5f81<\/span><\/p>\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u7ecf\u5178\u8bed\u5f55<\/span><\/p>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u9752\u94dc<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">catch(Exception e){}<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">&#034;\u5148\u8dd1\u8d77\u6765\u518d\u8bf4&#034;<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u9ec4\u91d1<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u7cbe\u786e\u6355\u83b7\u7279\u5b9a\u5f02\u5e38<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">&#034;\u8fd9\u4e2aSQLException\u6211\u6765\u5904\u7406&#034;<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u738b\u8005<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p style=\"text-align:center\"><span style=\"color:#ed7976\">&#034;\u8bf7\u7ee7\u627f\u6211\u7684BaseBizException&#034;<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>try-catch-finally<\/h4>\n<p>try {<br \/>\n    \/\/ \u53ef\u80fd\u629b\u51fa\u5f02\u5e38\u7684\u4ee3\u7801<br \/>\n    int result &#061; 10 \/ 0;<br \/>\n} catch (ArithmeticException e) {<br \/>\n    \/\/ \u5904\u7406\u7279\u5b9a\u5f02\u5e38<br \/>\n    System.out.println(&#034;\u9664\u6570\u4e0d\u80fd\u4e3a\u96f6&#034;);<br \/>\n} catch (Exception e) {<br \/>\n    \/\/ \u5904\u7406\u5176\u4ed6\u5f02\u5e38<br \/>\n    System.out.println(&#034;\u53d1\u751f\u5f02\u5e38&#xff1a;&#034; &#043; e.getMessage());<br \/>\n} finally {<br \/>\n    \/\/ \u65e0\u8bba\u662f\u5426\u53d1\u751f\u5f02\u5e38\u90fd\u4f1a\u6267\u884c\u7684\u4ee3\u7801<br \/>\n    System.out.println(&#034;\u6267\u884cfinally\u5757&#034;);<br \/>\n}<\/p>\n<h4>throws\u548cthrow<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u200cthrows\u200c&#xff1a;\u58f0\u660e\u65b9\u6cd5\u53ef\u80fd\u629b\u51fa\u7684\u5f02\u5e38<\/p>\n<p>public void readFile() throws IOException {<br \/>\n    \/\/ \u65b9\u6cd5\u4ee3\u7801<br \/>\n}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u200cthrow\u200c&#xff1a;\u4e3b\u52a8\u629b\u51fa\u5f02\u5e38\u5bf9\u8c61<\/p>\n<p>public void validateAge(int age) {<br \/>\n    if (age &lt; 0) {<br \/>\n        throw new IllegalArgumentException(&#034;\u5e74\u9f84\u4e0d\u80fd\u4e3a\u8d1f\u6570&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<h4>\u81ea\u5b9a\u4e49\u5f02\u5e38<\/h4>\n<p>\u901a\u8fc7\u7ee7\u627fException\u6216RuntimeException\u521b\u5efa\u81ea\u5b9a\u4e49\u5f02\u5e38&#xff1a;<\/p>\n<p>\/\/ \u81ea\u5b9a\u4e49\u68c0\u67e5\u5f02\u5e38<br \/>\npublic class MyCheckedException extends Exception {<br \/>\n    public MyCheckedException(String message) {<br \/>\n        super(message);<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u81ea\u5b9a\u4e49\u8fd0\u884c\u65f6\u5f02\u5e38<br \/>\npublic class MyRuntimeException extends RuntimeException {<br \/>\n    public MyRuntimeException(String message) {<br \/>\n        super(message);<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u4f7f\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38<br \/>\npublic void process() throws MyCheckedException {<br \/>\n    if (someCondition) {<br \/>\n        throw new MyCheckedException(&#034;\u81ea\u5b9a\u4e49\u5f02\u5e38\u4fe1\u606f&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<h4>\u4e00\u3001\u5f02\u5e38\u5904\u7406\u539f\u5219\u200c<\/h4>\n<li>\u200c\u68c0\u67e5\u5f02\u5e38\u200c&#xff1a;\u5fc5\u987b\u901a\u8fc7try-catch\u6355\u83b7\u6216throws\u58f0\u660e\u629b\u51fa\u3002<\/li>\n<li>\u200c\u975e\u68c0\u67e5\u5f02\u5e38\u200c&#xff1a;\u4f18\u5148\u901a\u8fc7\u903b\u8f91\u9884\u9632&#xff08;\u5982\u5224\u7a7a\u3001\u7d22\u5f15\u6821\u9a8c&#xff09;&#xff0c;\u53ef\u9009\u62e9\u6027\u6355\u83b7\u3002<\/li>\n<li>\u200c\u9519\u8bef&#xff08;Error&#xff09;\u200c&#xff1a;\u65e0\u6cd5\u4fee\u590d&#xff0c;\u9700\u4f18\u5316\u4ee3\u7801\u6216\u8c03\u6574JVM\u53c2\u6570\u3002<\/li>\n<p>\u200c\u6700\u4f73\u5b9e\u8df5\u200c&#xff1a;<\/p>\n<ul>\n<li>\u4f18\u5148\u6355\u83b7\u7279\u5b9a\u5f02\u5e38&#xff08;\u5982FileNotFoundException\u800c\u975e\u6cdb\u5316\u7684Exception&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528try-with-resources\u81ea\u52a8\u91ca\u653e\u8d44\u6e90&#xff08;\u5982\u6587\u4ef6\u6d41&#xff09;\u3002<\/li>\n<li>\u65e5\u5fd7\u8bb0\u5f55\u4ee3\u66ffe.printStackTrace()\u3002<\/li>\n<\/ul>\n<h4>\u00a0\u4e8c\u3001\u7cbe\u51c6\u6355\u83b7\u4e0e\u5206\u7c7b\u5904\u7406<\/h4>\n<li>\n<p>\u200c\u533a\u5206\u5f02\u5e38\u7c7b\u578b\u200c<\/p>\n<ul>\n<li>\u200cChecked\u5f02\u5e38\u200c&#xff08;\u5982IOException&#xff09;&#xff1a;\u5fc5\u987b\u663e\u5f0f\u5904\u7406&#xff08;try-catch\u6216\u5728\u65b9\u6cd5\u7b7e\u540d\u58f0\u660ethrows&#xff09;&#xff0c;\u9002\u7528\u4e8e\u53ef\u9884\u89c1\u7684\u9519\u8bef&#xff08;\u5982\u6587\u4ef6\u7f3a\u5931&#xff09;\u3002<\/li>\n<li>\u200cUnchecked\u5f02\u5e38\u200c&#xff08;\u5982NullPointerException&#xff09;&#xff1a;\u901a\u5e38\u7531\u4ee3\u7801\u903b\u8f91\u9519\u8bef\u5f15\u8d77&#xff0c;\u7f16\u8bd1\u671f\u4e0d\u5f3a\u5236\u5904\u7406&#xff0c;\u9700\u901a\u8fc7\u4ee3\u7801\u5065\u58ee\u6027\u89c4\u907f\u3002<\/li>\n<li>\u200cError\u200c&#xff08;\u5982OutOfMemoryError&#xff09;&#xff1a;\u8868\u793a\u7cfb\u7edf\u7ea7\u4e25\u91cd\u9519\u8bef&#xff0c;\u901a\u5e38\u65e0\u6cd5\u6062\u590d&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u65e0\u9700\u5904\u7406\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u200c\u907f\u514d\u5bbd\u6cdb\u6355\u83b7\u200c \u7981\u6b62\u76f4\u63a5\u6355\u83b7Exception\u6216Throwable&#xff0c;\u5e94\u7ec6\u5316\u5230\u5177\u4f53\u5f02\u5e38\u7c7b\u578b&#xff0c;\u9632\u6b62\u9690\u85cf\u6f5c\u5728\u95ee\u9898\u3002<\/p>\n<p> try { \/* \u6587\u4ef6\u64cd\u4f5c *\/ }<br \/>\ncatch (FileNotFoundException e) { \/* \u5177\u4f53\u5904\u7406 *\/ }<br \/>\ncatch (IOException e) { \/* \u66f4\u5bbd\u6cdb\u7684I\/O\u5904\u7406 *\/ }<br \/>\n \/\/ \u5b50\u7c7b\u5728\u524d&#xff0c;\u7236\u7c7b\u5728\u540e\n <\/li>\n<h4>\ufe0f\u4e09\u3001\u8d44\u6e90\u7ba1\u7406\u4e0e\u6e05\u7406<\/h4>\n<li>\n<p>\u200cfinally\u5757\u7684\u5f3a\u5236\u6027\u200c \u65e0\u8bba\u662f\u5426\u53d1\u751f\u5f02\u5e38&#xff0c;finally\u5757\u59cb\u7ec8\u6267\u884c&#xff0c;\u7528\u4e8e\u91ca\u653e\u8d44\u6e90&#xff08;\u5982\u5173\u95ed\u6587\u4ef6\u6d41\u3001\u6570\u636e\u5e93\u8fde\u63a5&#xff09;&#xff1a;<\/p>\n<p> FileReader reader &#061; null;<br \/>\ntry {<br \/>\n    reader &#061; new FileReader(&#034;file.txt&#034;);<br \/>\n} catch (IOException e) {<br \/>\n    System.out.println(&#034;\u8bfb\u53d6\u5931\u8d25: &#034; &#043; e.getMessage());<br \/>\n} finally {<br \/>\n    if (reader !&#061; null) reader.close();  \/\/ \u786e\u4fdd\u8d44\u6e90\u91ca\u653e<br \/>\n}\n <\/li>\n<li>\n<p>\u200ctry-with-resources\u4f18\u5316\u200c&#xff08;Java 7&#043;&#xff09; \u81ea\u52a8\u5173\u95ed\u5b9e\u73b0AutoCloseable\u63a5\u53e3\u7684\u8d44\u6e90&#xff0c;\u907f\u514dfinally\u5757\u5197\u4f59\u4ee3\u7801\u3002\u82e5\u4e1a\u52a1\u903b\u8f91\u548c\u8d44\u6e90\u5173\u95ed\u5747\u629b\u51fa\u5f02\u5e38&#xff0c;\u5173\u95ed\u5f02\u5e38\u4f1a\u88ab\u6807\u8bb0\u4e3asuppressed\u9644\u52a0\u5230\u4e3b\u5f02\u5e38&#xff1a;<\/p>\n<p> try (FileInputStream fis &#061; new FileInputStream(&#034;test.txt&#034;)) {<br \/>\n    \/\/ \u81ea\u52a8\u7ba1\u7406\u8d44\u6e90<br \/>\n} catch (IOException e) {<br \/>\n    e.getSuppressed();  \/\/ \u83b7\u53d6\u5173\u95ed\u8d44\u6e90\u65f6\u7684\u5f02\u5e38<br \/>\n}\n <\/li>\n<h4>\u56db\u3001\u81ea\u5b9a\u4e49\u5f02\u5e38\u4e0e\u5f02\u5e38\u94fe<\/h4>\n<li>\n<p>\u200c\u81ea\u5b9a\u4e49\u4e1a\u52a1\u5f02\u5e38\u200c \u5f53\u6807\u51c6\u5f02\u5e38\u65e0\u6cd5\u6ee1\u8db3\u4e1a\u52a1\u8bed\u4e49\u65f6&#xff08;\u5982\u4f59\u989d\u4e0d\u8db3\u3001\u8ba2\u5355\u8d85\u65f6&#xff09;&#xff0c;\u7ee7\u627fRuntimeException\u521b\u5efa\u81ea\u5b9a\u4e49\u5f02\u5e38&#xff0c;\u63d0\u5347\u53ef\u8bfb\u6027&#xff1a;<\/p>\n<p> public class BalanceInsufficientException extends RuntimeException {<br \/>\n    public BalanceInsufficientException(String message) { super(message); }<br \/>\n}\n <\/li>\n<li>\n<p>\u200c\u5f02\u5e38\u94fe\u4f20\u9012\u4e0a\u4e0b\u6587\u200c \u6355\u83b7\u539f\u59cb\u5f02\u5e38\u540e\u629b\u51fa\u81ea\u5b9a\u4e49\u5f02\u5e38\u65f6&#xff0c;\u901a\u8fc7\u6784\u9020\u5668\u4f20\u9012\u539f\u59cb\u5f02\u5e38&#xff0c;\u4fdd\u7559\u5b8c\u6574\u7684\u9519\u8bef\u5806\u6808&#xff1a;<\/p>\n<p> try { \/* \u4e1a\u52a1\u903b\u8f91 *\/ }<br \/>\ncatch (SQLException e) {<br \/>\n    throw new ServiceException(&#034;\u6570\u636e\u5e93\u64cd\u4f5c\u5931\u8d25&#034;, e);  \/\/ \u4fdd\u7559\u539f\u59cb\u5f02\u5e38\u4fe1\u606f<br \/>\n}\n <\/li>\n<h4>\u4e94\u3001\u8fdb\u9636\u5b9e\u8df5&#xff1a;\u7edf\u4e00\u5f02\u5e38\u5904\u7406<\/h4>\n<p>\u5728Web\u5e94\u7528\u4e2d&#xff0c;\u901a\u8fc7\u200c\u5168\u5c40\u5f02\u5e38\u5904\u7406\u5668\u200c&#xff08;\u5982Spring\u7684&#064;ControllerAdvice&#xff09;\u96c6\u4e2d\u5904\u7406\u5f02\u5e38&#xff0c;\u907f\u514d\u91cd\u590d\u4ee3\u7801&#xff1a;<\/p>\n<ul>\n<li>\u6355\u83b7\u63a7\u5236\u5668\u5c42\u629b\u51fa\u7684\u5f02\u5e38&#xff0c;\u7edf\u4e00\u8f6c\u6362\u4e3a\u7528\u6237\u53cb\u597d\u7684\u9519\u8bef\u54cd\u5e94\u3002<\/li>\n<li>\u7ed3\u5408\u65e5\u5fd7\u6846\u67b6\u8bb0\u5f55\u5f02\u5e38\u7ec6\u8282&#xff08;\u5982\u5806\u6808\u3001\u8bf7\u6c42\u53c2\u6570&#xff09;&#xff0c;\u4fbf\u4e8e\u6392\u67e5\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p>\/\/\u91c7\u7528&#064;RestControllerAdvice\u7edf\u4e00\u7ba1\u7406\u5f02\u5e38&#xff1a;<br \/>\n&#064;RestControllerAdvice<br \/>\npublic class GlobalExceptionHandler {<br \/>\n    \/\/ \u5904\u7406\u4e1a\u52a1\u81ea\u5b9a\u4e49\u5f02\u5e38<br \/>\n    &#064;ExceptionHandler(BusinessException.class)<br \/>\n    public ResponseResult handleBusinessException(BusinessException e) {<br \/>\n        return ResponseResult.fail(e.getCode(), e.getMessage());<br \/>\n    }<br \/>\n    \/\/ \u5904\u7406\u53c2\u6570\u6821\u9a8c\u5f02\u5e38<br \/>\n    &#064;ExceptionHandler(BindException.class)<br \/>\n    public ResponseResult handleBindException(BindException e) {<br \/>\n        return ResponseResult.fail(400, &#034;\u53c2\u6570\u9519\u8bef&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\u200c\/\u4f18\u52bf\u200c&#xff1a;\u96c6\u4e2d\u5904\u7406\u5f02\u5e38\u903b\u8f91&#xff0c;\u964d\u4f4e\u4ee3\u7801\u5197\u4f59\u3002 <\/p>\n<h4>\u26a0\ufe0f \u5173\u952e\u7981\u5fcc<\/h4>\n<ul>\n<li>\u200c\u7981\u6b62\u541e\u6ca1\u5f02\u5e38\u200c&#xff1a;\u7a7acatch\u5757\u6216\u4ec5\u6253\u5370\u65e5\u5fd7\u800c\u4e0d\u5904\u7406\u4f1a\u5bfc\u81f4\u95ee\u9898\u88ab\u63a9\u76d6\u3002<\/li>\n<li>\u200c\u907f\u514d\u8fc7\u5ea6\u4f7f\u7528Checked\u5f02\u5e38\u200c&#xff1a;\u8fc7\u5ea6\u58f0\u660ethrows\u4f1a\u6c61\u67d3\u4ee3\u7801&#xff0c;\u964d\u4f4e\u7075\u6d3b\u6027\u3002<\/li>\n<li>\u200c\u65e5\u5fd7\u89c4\u8303\u200c&#xff1a;\u8bb0\u5f55\u5f02\u5e38\u65f6\u9700\u5305\u542b\u5b8c\u6574\u5806\u6808&#xff08;e.printStackTrace()\u4e0d\u9002\u7528\u751f\u4ea7\u73af\u5883&#xff09;&#xff0c;\u63a8\u8350log.error(&#034;\u4e0a\u4e0b\u6587&#034;, e)\u3002<\/li>\n<\/ul>\n<p>\u5173\u952e\u70b9\u8bf4\u660e&#xff1a;\u200c<\/p>\n<li>\u7279\u5b9a\u5f02\u5e38\u4f18\u5148\u6355\u83b7&#xff08;\u5982\u5148\u6355\u83b7NullPointerException\u518d\u6355\u83b7\u901a\u7528Exception&#xff09;<\/li>\n<li>finally\u5757\u786e\u4fdd\u6587\u4ef6\/\u7f51\u7edc\u8fde\u63a5\u7b49\u8d44\u6e90\u91ca\u653e<\/li>\n<li>\u53d7\u68c0\u5f02\u5e38\u5fc5\u987b\u5904\u7406&#xff08;\u6355\u83b7\u6216throws&#xff09;<\/li>\n<li>\u81ea\u5b9a\u4e49\u5f02\u5e38\u5e94\u7ee7\u627fException\u6216RuntimeException<\/li>\n<li>\u5b9e\u9645\u5f00\u53d1\u4e2d\u5e94\u4f7f\u7528\u65e5\u5fd7\u6846\u67b6&#xff08;\u5982Log4j&#xff09;\u66ff\u4ee3printStackTrace()<\/li>\n<p>\u901a\u8fc7\u5206\u5c42\u5904\u7406\u4e0d\u540c\u5f02\u5e38\u7c7b\u578b&#xff0c;\u53ef\u4ee5\u6784\u5efa\u5065\u58ee\u7684\u5bb9\u9519\u7cfb\u7edf\u3002\u4f18\u96c5\u5f02\u5e38\u5904\u7406\u7684\u6838\u5fc3\u5728\u4e8e&#xff1a;\u200c\u7cbe\u51c6\u6355\u83b7\u3001\u660e\u786e\u5206\u7c7b\u3001\u8d44\u6e90\u5b89\u5168\u3001\u4e0a\u4e0b\u6587\u4f20\u9012\u200c\u3002<\/p>\n<hr \/>\n<h2>\u4f0d\u3001\u5f02\u5e38\u5904\u7406\u7684\u4e09\u4e2a\u6838\u5fc3\u7ef4\u5ea6<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5f02\u5e38\u5904\u7406\u7684\u4e09\u4e2a\u7ef4\u5ea6&#xff1a;\u9632\u5fa1\u6027\u7f16\u7a0b&#xff08;Defensive Programming&#xff09;\u3001\u5951\u7ea6\u5f0f\u8bbe\u8ba1&#xff08;Design by Contract&#xff09;\u3001\u5f39\u6027\u67b6\u6784&#xff08;Resilient Architecture&#xff09;\u3002<\/p>\n<h4>\u4e00\u3001\u9632\u5fa1\u6027\u7f16\u7a0b&#xff08;Defensive Programming&#xff09;\u200c<\/h4>\n<p>\u200c\u6838\u5fc3\u601d\u60f3\u200c&#xff1a;\u901a\u8fc7\u9884\u5224\u6f5c\u5728\u9519\u8bef\u5e76\u4e3b\u52a8\u9632\u62a4&#xff0c;\u589e\u5f3a\u4ee3\u7801\u5065\u58ee\u6027\u3002<\/p>\n<ul>\n<li>\u200c\u8f93\u5165\u9a8c\u8bc1\u200c&#xff1a;\u5bf9\u6240\u6709\u5916\u90e8\u8f93\u5165&#xff08;\u5982\u7528\u6237\u8f93\u5165\u3001API\u54cd\u5e94&#xff09;\u8fdb\u884c\u4e25\u683c\u6821\u9a8c&#xff0c;\u907f\u514d\u975e\u6cd5\u6570\u636e\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002<\/li>\n<li>\u200c\u8fb9\u754c\u68c0\u67e5\u200c&#xff1a;\u5904\u7406\u6570\u7ec4\u8d8a\u754c\u3001\u7a7a\u6307\u9488\u7b49\u5e38\u89c1\u8fd0\u884c\u65f6\u5f02\u5e38&#xff0c;\u4f8b\u5982\u901a\u8fc7if (obj !&#061; null)\u89c4\u907f\u7a7a\u6307\u9488\u95ee\u9898\u3002<\/li>\n<li>\u200c\u9ed8\u8ba4\u5b89\u5168\u7b56\u7565\u200c&#xff1a;\u5982\u8d44\u6e90\u91ca\u653e\u540e\u7f6e\u7a7a\u5f15\u7528\u3001\u6587\u4ef6\u64cd\u4f5c\u540e\u5173\u95ed\u6d41&#xff0c;\u9632\u6b62\u8d44\u6e90\u6cc4\u6f0f\u3002<\/li>\n<li>\u200c\u6848\u4f8b\u200c&#xff1a;Android\u5f00\u53d1\u4e2d\u901a\u8fc7Monkey Test\u6a21\u62df\u968f\u673a\u64cd\u4f5c\u9a8c\u8bc1\u7cfb\u7edf\u6297\u5f02\u5e38\u80fd\u529b\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u200c\u4e8c\u3001\u5951\u7ea6\u5f0f\u8bbe\u8ba1&#xff08;Design by Contract, DbC&#xff09;\u200c<\/h4>\n<p>\u200c\u6838\u5fc3\u601d\u60f3\u200c&#xff1a;\u901a\u8fc7\u5f62\u5f0f\u5316\u5951\u7ea6\u660e\u786e\u6a21\u5757\u95f4\u7684\u8d23\u4efb\u8fb9\u754c&#xff0c;\u4ee5\u65ad\u8a00&#xff08;Assertions&#xff09;\u5f3a\u5236\u6267\u884c\u4ea4\u4e92\u89c4\u5219\u3002<\/p>\n<ul>\n<li>\u200c\u5951\u7ea6\u4e09\u8981\u7d20\u200c&#xff1a;\n<li>\u200c\u5148\u9a8c\u6761\u4ef6&#xff08;Preconditions&#xff09;\u200c&#xff1a;\u8c03\u7528\u65b9\u9700\u6ee1\u8db3\u7684\u6761\u4ef6&#xff08;\u5982\u53c2\u6570\u975e\u7a7a&#xff09;\u3002<\/li>\n<li>\u200c\u540e\u9a8c\u6761\u4ef6&#xff08;Postconditions&#xff09;\u200c&#xff1a;\u88ab\u8c03\u7528\u65b9\u9700\u4fdd\u8bc1\u7684\u7ed3\u679c&#xff08;\u5982\u8fd4\u56de\u503c\u8303\u56f4&#xff09;\u3002<\/li>\n<li>\u200c\u7c7b\u4e0d\u53d8\u5f0f&#xff08;Invariants&#xff09;\u200c&#xff1a;\u5bf9\u8c61\u72b6\u6001\u5fc5\u987b\u59cb\u7ec8\u6ee1\u8db3\u7684\u7ea6\u675f&#xff08;\u5982\u8d26\u6237\u4f59\u989d\u22650&#xff09;\u3002<\/li>\n<\/li>\n<li>\u200c\u5b9e\u73b0\u65b9\u5f0f\u200c&#xff1a;\n<ul>\n<li>Eiffel\u8bed\u8a00\u539f\u751f\u652f\u6301DbC\u8bed\u6cd5\u3002<\/li>\n<li>Java\u53ef\u901a\u8fc7assert\u5173\u952e\u5b57\u6216\u5de5\u5177&#xff08;\u5982JML&#xff09;\u5b9e\u73b0\u5951\u7ea6\u6821\u9a8c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u200c\u5f02\u5e38\u5904\u7406\u539f\u5219\u200c&#xff1a;\u5951\u7ea6\u8fdd\u80cc\u65f6\u629b\u51fa\u5f02\u5e38&#xff0c;\u4f46\u5f02\u5e38\u5904\u7406\u903b\u8f91\u4e0d\u5c5e\u4e8e\u5951\u7ea6\u672c\u8eab\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u200c\u4e09\u3001\u5f39\u6027\u67b6\u6784&#xff08;Resilient Architecture&#xff09;\u200c<\/h4>\n<p>\u200c\u6838\u5fc3\u601d\u60f3\u200c&#xff1a;\u901a\u8fc7\u7cfb\u7edf\u8bbe\u8ba1\u5b9e\u73b0\u6545\u969c\u9694\u79bb\u3001\u81ea\u52a8\u6062\u590d\u548c\u52a8\u6001\u6269\u5c55\u3002<\/p>\n<ul>\n<li>\u200c\u5173\u952e\u6280\u672f\u200c&#xff1a;\n<li>\u200c\u5355\u5143\u5316\u67b6\u6784&#xff08;Cell-Based&#xff09;\u200c&#xff1a;\u5c06\u7cfb\u7edf\u5212\u5206\u4e3a\u72ec\u7acb\u5355\u5143&#xff0c;\u5355\u70b9\u6545\u969c\u4e0d\u5f71\u54cd\u5168\u5c40\u3002<\/li>\n<li>\u200c\u65ad\u8def\u5668\u6a21\u5f0f\u200c&#xff1a;\u901a\u8fc7Resilience4j\u7b49\u5de5\u5177\u5b9e\u73b0\u6545\u969c\u7194\u65ad&#xff0c;\u907f\u514d\u7ea7\u8054\u5d29\u6e83\u3002<\/li>\n<li>\u200c\u5f02\u6b65\u5904\u7406\u200c&#xff1a;\u6d88\u606f\u961f\u5217\u89e3\u8026\u7ec4\u4ef6&#xff0c;\u786e\u4fdd\u90e8\u5206\u670d\u52a1\u5b95\u673a\u65f6\u6838\u5fc3\u6d41\u7a0b\u4ecd\u53ef\u8fd0\u884c\u3002<\/li>\n<\/li>\n<li>\u200c\u8bc4\u4f30\u6307\u6807\u200c&#xff1a;\u6545\u969c\u5bb9\u5fcd\u6027\u3001\u8d1f\u8f7d\u5747\u8861\u80fd\u529b\u3001\u81ea\u52a8\u5316\u8fd0\u7ef4\u6c34\u5e73\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u200c\u4e09\u7ef4\u5ea6\u5bf9\u6bd4\u4e0e\u534f\u540c\u200c<\/h4>\n<table>\n<tr>\u200c\u7ef4\u5ea6\u200c\u200c\u5173\u6ce8\u70b9\u200c\u200c\u5178\u578b\u6280\u672f\/\u5de5\u5177\u200c\u200c\u9002\u7528\u573a\u666f\u200c<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:center\">\u9632\u5fa1\u6027\u7f16\u7a0b<\/td>\n<td style=\"text-align:center\">\u4ee3\u7801\u7ea7\u9519\u8bef\u9884\u9632<\/td>\n<td style=\"text-align:center\">\u8f93\u5165\u6821\u9a8c\u3001\u7a7a\u6307\u9488\u68c0\u67e5<\/td>\n<td style=\"text-align:center\">\u5c40\u90e8\u903b\u8f91\u9632\u62a4<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">\u5951\u7ea6\u5f0f\u8bbe\u8ba1<\/td>\n<td style=\"text-align:center\">\u63a5\u53e3\u884c\u4e3a\u89c4\u8303\u5316<\/td>\n<td style=\"text-align:center\">Eiffel\u65ad\u8a00\u3001JML\u5951\u7ea6\u8bed\u8a00<\/td>\n<td style=\"text-align:center\">\u6a21\u5757\u95f4\u534f\u4f5c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">\u5f39\u6027\u67b6\u6784<\/td>\n<td style=\"text-align:center\">\u7cfb\u7edf\u7ea7\u5bb9\u9519<\/td>\n<td style=\"text-align:center\">\u5355\u5143\u5316\u67b6\u6784\u3001\u65ad\u8def\u5668\u6a21\u5f0f<\/td>\n<td style=\"text-align:center\">\u5206\u5e03\u5f0f\u7cfb\u7edf\u9ad8\u53ef\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e09\u8005\u9700\u7ed3\u5408\u4f7f\u7528&#xff1a;\u9632\u5fa1\u6027\u7f16\u7a0b\u4fdd\u969c\u4ee3\u7801\u57fa\u7840\u5065\u58ee\u6027&#xff0c;\u5951\u7ea6\u5f0f\u8bbe\u8ba1\u89c4\u8303\u6a21\u5757\u4ea4\u4e92&#xff0c;\u5f39\u6027\u67b6\u6784\u5e94\u5bf9\u5168\u5c40\u6027\u6545\u969c\u3002<\/p>\n<hr \/>\n<h2>\u9646\u3001\u7a0b\u5e8f\u5458\u5f02\u5e38\u7269\u8bed<\/h2>\n<h4>1 \u300a\u5f53\u5f02\u5e38\u9047\u5230\u73b0\u5b9e\u300b<\/h4>\n<p>try { \u5973\u670b\u53cb.rememberAnniversary(); \/\/ \u7eaa\u5ff5\u65e5\u63d0\u9192 }<br \/>\ncatch (MemoryOverflowException e) {<br \/>\n    \u4e70\u82b1().setFlowers(999); \/\/ \u7d27\u6025\u8865\u6551<br \/>\n} finally {<br \/>\n    \u5de5\u8d44\u5361.withdraw(\u91d1\u989d.ALL);<br \/>\n} <\/p>\n<h4>2 \u300a\u6d4b\u8bd5\u73af\u5883\u7684\u7384\u5b66\u300b<\/h4>\n<p>&#034;\u5728\u6211\u7684\u672c\u5730\u660e\u660e\u662f\u597d\u7684&#xff01;&#034; \u2014\u2014 \u8457\u540d\u6700\u540e\u4e00\u53e5\u8bdd&#xff0c;\u901a\u5e38\u51fa\u73b0\u5728&#xff1a;<\/p>\n<li>\n<p>\u4ee3\u7801\u521a\u4e0a\u6d4b\u8bd5\u73af\u5883\u65f6<\/p>\n<\/li>\n<li>\n<p>\u6f14\u793a\u7ed9\u9886\u5bfc\u770b\u7684\u524d\u4e00\u5206\u949f<\/p>\n<\/li>\n<li>\n<p>\u4e0a\u7ebf\u540e\u534a\u591c\u4e09\u70b9<\/p>\n<\/li>\n<h4>3\u00a0 \u00a0\u5f02\u5e38\u5904\u7406\u9ed1\u8bdd\u8bcd\u5178<\/h4>\n<ul>\n<li>\n<p>&#034;\u8fd9\u662f\u7279\u6027\u4e0d\u662fbug&#034;&#xff1a;\u5f53\u5f02\u5e38\u5904\u7406\u903b\u8f91\u6bd4\u4e3b\u6d41\u7a0b\u8fd8\u590d\u6742\u65f6<\/p>\n<\/li>\n<li>\n<p>&#034;\u5148\u8fd9\u6837\u540e\u9762\u518d\u4f18\u5316&#034;&#xff1a;catch\u5757\u91cc\u5199\u7740TODO\u7684\u4ee3\u7801<\/p>\n<\/li>\n<li>\n<p>&#034;\u7406\u8bba\u4e0a\u4e0d\u5e94\u8be5\u53d1\u751f&#034;&#xff1a;\u7528\u4e8e\u89e3\u91ca\u4e3a\u4ec0\u4e48\u6ca1\u5904\u7406\u67d0\u4e2a\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>&#034;\u5386\u53f2\u9057\u7559\u95ee\u9898&#034;&#xff1a;\u89e3\u91ca\u4e3a\u4ec0\u4e48\u5f02\u5e38\u5904\u7406\u5199\u5f97\u50cf\u8ff7\u5bab<\/p>\n<\/li>\n<\/ul>\n<h4>4 \u300a\u6d88\u5931\u7684\u53d8\u91cf\u300b\u60ac\u7591\u5267<\/h4>\n<p>public void \u4fa6\u63a2\u5267() {<br \/>\n    String \u51f6\u624b &#061; null;<br \/>\n    try { System.out.println(\u51f6\u624b.length()); \/\/ \u51f6\u5668\u662fNPE&#xff01; }<br \/>\n        catch (NullPointerException e) {<br \/>\n            System.out.println(&#034;\u67ef\u5357\u9644\u4f53&#xff1a;\u771f\u76f8\u53ea\u6709\u4e00\u4e2a\u2014\u2014\u4f60\u5fd8\u4e86\u521d\u59cb\u5316&#xff01;&#034;);<br \/>\n        }<br \/>\n} <\/p>\n<h4>5 \u300afinally\u7684\u5014\u5f3a\u300b\u52b1\u5fd7\u7247<\/h4>\n<p>try { throw new \u7532\u65b9\u9700\u6c42\u53d8\u66f4\u5f02\u5e38(); }<br \/>\nfinally { System.out.println(&#034;\u7a0b\u5e8f\u5458\u64e6\u5e72\u773c\u6cea\u7ee7\u7eedcoding&#8230;&#034;); } <\/p>\n<hr \/>\n<h2>\u4e03\u3001\u5f69\u86cb<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"141\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812064951-689ae40f0205b.png\" width=\"387\" \/><\/p>\n<p style=\"text-align:center\">\u5982\u679c\u601d\u5ff5\u6709\u58f0\u97f3<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"195\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812064952-689ae410623d7.png\" width=\"195\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4\u6b21\u3002\u300aJava\u5f02\u5e38\u5904\u7406\u4f53\u7cfb\u89e3\u6790\u300b\u6458\u8981\uff1a\u672c\u6587\u7cfb\u7edf\u9610\u8ff0\u4e86Java\u5f02\u5e38\u5904\u7406\u673a\u5236\uff0c\u4ece\u5f02\u5e38\u5206\u7c7b\uff08Error\/Exception\uff09\u3001\u5e38\u89c1\u5f02\u5e38\u7c7b\u578b\uff08NPE\u3001IO\u5f02\u5e38\u7b49\uff09\u5230\u5f02\u5e38\u5904\u7406\u7684\u4e09\u91cd\u7ef4\u5ea6\uff1a\u9632\u5fa1\u6027\u7f16\u7a0b\u901a\u8fc7\u8f93\u5165\u6821\u9a8c\u9884\u9632\u9519\u8bef\uff1b\u5951\u7ea6\u5f0f\u8bbe\u8ba1\u89c4\u8303\u6a21\u5757\u4ea4\u4e92\uff1b\u5f39\u6027\u67b6\u6784\u786e\u4fdd\u7cfb\u7edf\u7ea7\u5bb9\u9519\u3002\u6587\u7ae0\u8be6\u89e3\u4e86try-catch-finally\u3001throws\/throw\u7b49\u6838\u5fc3\u8bed\u6cd5\uff0c\u5f3a\u8c03\u5e94\u7cbe\u786e\u6355\u83b7\u7279\u5b9a\u5f02\u5e38\u3001\u5408\u7406\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38\uff0c\u5e76\u63a8\u8350try-with-resources\u7ba1\u7406\u8d44\u6e90\u3002\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u539f\u5219\u4e0e\u5206\u5c42\u5904\u7406\u7b56\u7565\uff0c\u53ef\u6784\u5efa\u5065\u58ee\u7684\u5bb9\u9519\u7cfb\u7edf\u3002\u6587\u4e2d\u7a7f\u63d2\u7a0b\u5e8f\u5458\u5e7d\u9ed8\u6bb5\u5b50\uff0c\u751f\u52a8<\/p>\n","protected":false},"author":2,"featured_media":53656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5465,99,3332,5464,190,5466],"topic":[],"class_list":{"0":"post-53661","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-server","8":"tag-exception","9":"tag-java","12":"tag-190","13":"tag-5466"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/53661.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4\u6b21\u3002\u300aJava\u5f02\u5e38\u5904\u7406\u4f53\u7cfb\u89e3\u6790\u300b\u6458\u8981\uff1a\u672c\u6587\u7cfb\u7edf\u9610\u8ff0\u4e86Java\u5f02\u5e38\u5904\u7406\u673a\u5236\uff0c\u4ece\u5f02\u5e38\u5206\u7c7b\uff08Error\/Exception\uff09\u3001\u5e38\u89c1\u5f02\u5e38\u7c7b\u578b\uff08NPE\u3001IO\u5f02\u5e38\u7b49\uff09\u5230\u5f02\u5e38\u5904\u7406\u7684\u4e09\u91cd\u7ef4\u5ea6\uff1a\u9632\u5fa1\u6027\u7f16\u7a0b\u901a\u8fc7\u8f93\u5165\u6821\u9a8c\u9884\u9632\u9519\u8bef\uff1b\u5951\u7ea6\u5f0f\u8bbe\u8ba1\u89c4\u8303\u6a21\u5757\u4ea4\u4e92\uff1b\u5f39\u6027\u67b6\u6784\u786e\u4fdd\u7cfb\u7edf\u7ea7\u5bb9\u9519\u3002\u6587\u7ae0\u8be6\u89e3\u4e86try-catch-finally\u3001throws\/throw\u7b49\u6838\u5fc3\u8bed\u6cd5\uff0c\u5f3a\u8c03\u5e94\u7cbe\u786e\u6355\u83b7\u7279\u5b9a\u5f02\u5e38\u3001\u5408\u7406\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38\uff0c\u5e76\u63a8\u8350try-with-resources\u7ba1\u7406\u8d44\u6e90\u3002\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u539f\u5219\u4e0e\u5206\u5c42\u5904\u7406\u7b56\u7565\uff0c\u53ef\u6784\u5efa\u5065\u58ee\u7684\u5bb9\u9519\u7cfb\u7edf\u3002\u6587\u4e2d\u7a7f\u63d2\u7a0b\u5e8f\u5458\u5e7d\u9ed8\u6bb5\u5b50\uff0c\u751f\u52a8\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/53661.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-12T06:49:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812064947-689ae40bb9f3c.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/53661.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/53661.html\",\"name\":\"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-12T06:49:53+00:00\",\"dateModified\":\"2025-08-12T06:49:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/53661.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/53661.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/53661.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/53661.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4\u6b21\u3002\u300aJava\u5f02\u5e38\u5904\u7406\u4f53\u7cfb\u89e3\u6790\u300b\u6458\u8981\uff1a\u672c\u6587\u7cfb\u7edf\u9610\u8ff0\u4e86Java\u5f02\u5e38\u5904\u7406\u673a\u5236\uff0c\u4ece\u5f02\u5e38\u5206\u7c7b\uff08Error\/Exception\uff09\u3001\u5e38\u89c1\u5f02\u5e38\u7c7b\u578b\uff08NPE\u3001IO\u5f02\u5e38\u7b49\uff09\u5230\u5f02\u5e38\u5904\u7406\u7684\u4e09\u91cd\u7ef4\u5ea6\uff1a\u9632\u5fa1\u6027\u7f16\u7a0b\u901a\u8fc7\u8f93\u5165\u6821\u9a8c\u9884\u9632\u9519\u8bef\uff1b\u5951\u7ea6\u5f0f\u8bbe\u8ba1\u89c4\u8303\u6a21\u5757\u4ea4\u4e92\uff1b\u5f39\u6027\u67b6\u6784\u786e\u4fdd\u7cfb\u7edf\u7ea7\u5bb9\u9519\u3002\u6587\u7ae0\u8be6\u89e3\u4e86try-catch-finally\u3001throws\/throw\u7b49\u6838\u5fc3\u8bed\u6cd5\uff0c\u5f3a\u8c03\u5e94\u7cbe\u786e\u6355\u83b7\u7279\u5b9a\u5f02\u5e38\u3001\u5408\u7406\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38\uff0c\u5e76\u63a8\u8350try-with-resources\u7ba1\u7406\u8d44\u6e90\u3002\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u539f\u5219\u4e0e\u5206\u5c42\u5904\u7406\u7b56\u7565\uff0c\u53ef\u6784\u5efa\u5065\u58ee\u7684\u5bb9\u9519\u7cfb\u7edf\u3002\u6587\u4e2d\u7a7f\u63d2\u7a0b\u5e8f\u5458\u5e7d\u9ed8\u6bb5\u5b50\uff0c\u751f\u52a8","og_url":"https:\/\/www.wsisp.com\/helps\/53661.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-12T06:49:53+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250812064947-689ae40bb9f3c.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/53661.html","url":"https:\/\/www.wsisp.com\/helps\/53661.html","name":"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-12T06:49:53+00:00","dateModified":"2025-08-12T06:49:53+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/53661.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/53661.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/53661.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4f18\u96c5\u5904\u7406\u5f02\u5e38\uff1aJava\u7a0b\u5e8f\u5458\u5fc5\u5907\u6280\u80fd"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/53661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=53661"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/53661\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/53656"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=53661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=53661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=53661"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=53661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}