{"id":1542,"date":"2026-06-03T08:40:55","date_gmt":"2026-06-03T00:40:55","guid":{"rendered":"https:\/\/yunyanglib.cn\/?p=1542"},"modified":"2026-06-03T08:40:57","modified_gmt":"2026-06-03T00:40:57","slug":"%e3%80%90java%e3%80%91java-%e5%bc%82%e5%b8%b8%e5%a4%84%e7%90%86%e6%9c%ba%e5%88%b6%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/yunyanglib.cn\/?p=1542","title":{"rendered":"\u3010Java\u3011Java \u5f02\u5e38\u5904\u7406\u673a\u5236\u8be6\u89e3"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5927\u5bb6\u597d\uff0c\u6700\u8fd1\u6574\u7406\u4e86 Java \u5f02\u5e38\u76f8\u5173\u7684\u77e5\u8bc6\u70b9\uff0c\u4eca\u5929\u7cfb\u7edf\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b Java \u7684\u5f02\u5e38\u5904\u7406\u673a\u5236\u3002\u5f02\u5e38\u662f\u5f00\u53d1\u4e2d\u907f\u4e0d\u5f00\u7684\u5185\u5bb9\uff0c\u5408\u7406\u5904\u7406\u5f02\u5e38\u80fd\u8ba9\u7a0b\u5e8f\u66f4\u52a0\u5065\u58ee\uff0c\u907f\u514d\u65e0\u6545\u5d29\u6e83\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4ec0\u4e48\u662f\u5f02\u5e38<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b80\u5355\u6765\u8bf4\uff0c<strong>\u5f02\u5e38<\/strong>\u5c31\u662f\u6253\u65ad\u7a0b\u5e8f\u6b63\u5e38\u6267\u884c\u6d41\u7a0b\u7684\u610f\u5916\u4e8b\u4ef6\u3002\u7a0b\u5e8f\u6309\u7167\u65e2\u5b9a\u903b\u8f91\u8fd0\u884c\u65f6\uff0c\u4e00\u65e6\u51fa\u73b0\u5f02\u5e38\uff0c\u4ee3\u7801\u5c31\u4f1a\u7ec8\u6b62\u6267\u884c\u3002\u5982\u679c\u4e0d\u505a\u4efb\u4f55\u5904\u7406\uff0c\u7a0b\u5e8f\u4f1a\u76f4\u63a5\u95ea\u9000\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u800c Java \u63d0\u4f9b\u4e86\u5b8c\u5584\u7684\u5f02\u5e38\u5904\u7406\u4f53\u7cfb\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3b\u52a8\u6355\u83b7\u3001\u5904\u7406\u5f02\u5e38\uff0c\u65e2\u4fdd\u8bc1\u6838\u5fc3\u4e1a\u52a1\u7ee7\u7eed\u8fd0\u884c\uff0c\u4e5f\u80fd\u7ed9\u7528\u6237\u53cb\u597d\u7684\u63d0\u793a\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Error \u4e0e Exception \u7684\u533a\u522b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Java \u4e2d\u6240\u6709\u5f02\u5e38\u548c\u9519\u8bef\u7684\u9876\u5c42\u7236\u7c7b\u662f<code>Throwable<\/code>\uff0c\u5b83\u4e3b\u8981\u5206\u4e3a\u4e24\u5927\u5206\u652f\uff1a<code>Error<\/code>\u548c<code>Exception<\/code>\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Error\uff08\u9519\u8bef\uff09<\/strong>\u5c5e\u4e8e\u7cfb\u7edf\u7ea7\u522b\u7684\u4e25\u91cd\u95ee\u9898\uff0c\u901a\u5e38\u662f\u865a\u62df\u673a\u3001\u786c\u4ef6\u5c42\u9762\u5f15\u53d1\u7684\u81f4\u547d\u9519\u8bef\uff0c<strong>\u4ee3\u7801\u5c42\u9762\u65e0\u6cd5\u6355\u83b7\u548c\u5904\u7406<\/strong>\u3002\u6bd4\u5982\u5185\u5b58\u6ea2\u51fa\u3001\u865a\u62df\u673a\u5d29\u6e83\u7b49\uff0c\u4e00\u65e6\u51fa\u73b0\uff0c\u7a0b\u5e8f\u57fa\u672c\u65e0\u6cd5\u6062\u590d\u3002\u793a\u4f8b\uff1a<code>OutOfMemoryError<\/code>\uff08\u5185\u5b58\u6ea2\u51fa\u9519\u8bef\uff09\u3002<\/li>\n\n\n\n<li><strong>Exception\uff08\u5f02\u5e38\uff09<\/strong>\u8fd9\u662f\u6211\u4eec\u65e5\u5e38\u5f00\u53d1\u91cd\u70b9\u5173\u6ce8\u7684\u90e8\u5206\uff0c\u4ee3\u8868\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u51fa\u73b0\u7684\u53ef\u4fee\u590d\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee3\u7801\u4e3b\u52a8\u6355\u83b7\u3001\u5904\u7406\u3002\u6bd4\u5982\u9664\u6570\u4e3a 0\u3001\u7a7a\u6307\u9488\u3001\u6587\u4ef6\u4e0d\u5b58\u5728\u7b49\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u53d7\u68c0\u5f02\u5e38\u4e0e\u8fd0\u884c\u65f6\u5f02\u5e38<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Exception<\/code>\u53c8\u5206\u4e3a<strong>Checked \u53d7\u68c0\u5f02\u5e38<\/strong>\u548c<strong>Unchecked \u975e\u53d7\u68c0\u5f02\u5e38\uff08\u8fd0\u884c\u65f6\u5f02\u5e38\uff09<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Checked \u53d7\u68c0\u5f02\u5e38<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u8bd1\u9636\u6bb5\u5c31\u4f1a\u88ab\u7f16\u8bd1\u5668\u68c0\u67e5\uff0c<strong>\u5fc5\u987b\u663e\u5f0f\u6355\u83b7\u6216\u8005\u5411\u4e0a\u629b\u51fa<\/strong>\uff0c\u5426\u5219\u4ee3\u7801\u76f4\u63a5\u7f16\u8bd1\u62a5\u9519\u3002\u8fd9\u7c7b\u5f02\u5e38\u5927\u591a\u548c\u5916\u90e8\u8d44\u6e90\u4ea4\u4e92\u6709\u5173\uff0c\u6bd4\u5982\u6587\u4ef6\u8bfb\u5199\u3001\u7f51\u7edc\u8bf7\u6c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e38\u89c1\uff1a<code>IOException<\/code>\u3001<code>ClassNotFoundException<\/code>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Unchecked \u8fd0\u884c\u65f6\u5f02\u5e38<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ee7\u627f\u81ea<code>RuntimeException<\/code>\uff0c\u7f16\u8bd1\u9636\u6bb5\u4e0d\u4f1a\u62a5\u9519\uff0c\u8fd0\u884c\u65f6\u624d\u4f1a\u89e6\u53d1\u3002\u8fd9\u7c7b\u5f02\u5e38\u5927\u591a\u662f\u4ee3\u7801\u4e66\u5199\u4e0d\u89c4\u8303\u5bfc\u81f4\u7684\uff0c\u7406\u8bba\u4e0a\u53ef\u4ee5\u901a\u8fc7\u63d0\u524d\u5224\u7a7a\u3001\u903b\u8f91\u6821\u9a8c\u89c4\u907f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e38\u89c1\uff1a\u7a7a\u6307\u9488\u3001\u9664\u6570\u4e3a\u96f6\u3001\u6570\u7ec4\u4e0b\u6807\u8d8a\u754c\u7b49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4ee3\u7801\u793a\u4f8b\uff1a\u8fd0\u884c\u65f6\u5f02\u5e38\uff08\u7b97\u672f\u5f02\u5e38\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ExceptionDemo {\n    public static void main(String&#91;] args) {\n        int a = 10;\n        int b = 0;\n        \/\/ \u9664\u6570\u4e3a0\uff0c\u8fd0\u884c\u65f6\u629b\u51faArithmeticException\n        int result = a \/ b;\n        System.out.println(result);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u7a0b\u5e8f\u4f1a\u76f4\u63a5\u629b\u51fa\u7b97\u672f\u5f02\u5e38\u5e76\u7ec8\u6b62\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001throw \u4e0e throws \u5173\u952e\u5b57<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u540d\u5b57\u76f8\u8fd1\uff0c\u4f46\u7528\u6cd5\u3001\u4f4d\u7f6e\u3001\u4f5c\u7528\u5b8c\u5168\u4e0d\u540c\uff0c\u662f\u9ad8\u9891\u8003\u70b9\uff0c\u4e5f\u662f\u5f00\u53d1\u5e38\u7528\u8bed\u6cd5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. throws<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u5728<strong>\u65b9\u6cd5\u58f0\u660e\u5904<\/strong>\uff0c\u4f5c\u7528\u662f<strong>\u58f0\u660e\u5f53\u524d\u65b9\u6cd5\u6709\u53ef\u80fd\u629b\u51fa\u7684\u5f02\u5e38<\/strong>\uff0c\u628a\u5f02\u5e38\u4ea4\u7ed9\u65b9\u6cd5\u7684\u8c03\u7528\u8005\u53bb\u5904\u7406\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u540c\u65f6\u58f0\u660e\u591a\u4e2a\u5f02\u5e38\uff0c\u7528\u9017\u53f7\u5206\u9694\uff1b<\/li>\n\n\n\n<li>\u4e3b\u8981\u7528\u4e8e\u5904\u7406\u53d7\u68c0\u5f02\u5e38\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4ee3\u7801\u793a\u4f8b\uff1athrows \u58f0\u660e\u5f02\u5e38<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.io.FileReader;\nimport java.io.IOException;\n\npublic class ThrowsDemo {\n    \/\/ \u58f0\u660e\u8be5\u65b9\u6cd5\u53ef\u80fd\u629b\u51faIOException\u53d7\u68c0\u5f02\u5e38\n    public static void readFile() throws IOException {\n        FileReader fr = new FileReader(\"test.txt\");\n        fr.close();\n    }\n\n    public static void main(String&#91;] args) throws IOException {\n        readFile();\n    }\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. throw<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u5728<strong>\u65b9\u6cd5\u5185\u90e8<\/strong>\uff0c\u4f5c\u7528\u662f<strong>\u624b\u52a8\u4e3b\u52a8\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\u5bf9\u8c61<\/strong>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e00\u6b21\u53ea\u80fd\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\u5bf9\u8c61\uff1b<\/li>\n\n\n\n<li>\u4e00\u822c\u7ed3\u5408\u6761\u4ef6\u5224\u65ad\u4f7f\u7528\uff0c\u81ea\u5b9a\u4e49\u5f02\u5e38\u573a\u666f\u4f7f\u7528\u8f83\u591a\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4ee3\u7801\u793a\u4f8b\uff1athrow \u4e3b\u52a8\u629b\u51fa\u5f02\u5e38<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ThrowDemo {\n    public static void checkAge(int age) {\n        if (age &lt; 0) {\n            \/\/ \u624b\u52a8\u629b\u51fa\u5f02\u5e38\u5bf9\u8c61\n            throw new IllegalArgumentException(\"\u5e74\u9f84\u4e0d\u80fd\u4e3a\u8d1f\u6570\uff01\");\n        }\n        System.out.println(\"\u5e74\u9f84\u6821\u9a8c\u901a\u8fc7\");\n    }\n\n    public static void main(String&#91;] args) {\n        checkAge(-5);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e24\u8005\u6838\u5fc3\u533a\u522b\u603b\u7ed3<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f4d\u7f6e\uff1a<code>throws<\/code>\u5728\u65b9\u6cd5\u7b7e\u540d\u540e\uff0c<code>throw<\/code>\u5728\u65b9\u6cd5\u4f53\u5185\uff1b<\/li>\n\n\n\n<li>\u5185\u5bb9\uff1a<code>throws<\/code>\u540e\u8ddf\u5f02\u5e38\u7c7b\u540d\uff0c<code>throw<\/code>\u540e\u8ddf\u5f02\u5e38\u5b9e\u4f8b\u5bf9\u8c61\uff1b<\/li>\n\n\n\n<li>\u6570\u91cf\uff1a<code>throws<\/code>\u53ef\u58f0\u660e\u591a\u4e2a\u5f02\u5e38\uff0c<code>throw<\/code>\u6bcf\u6b21\u4ec5\u629b\u51fa\u4e00\u4e2a\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ec0\u4e48\u65f6\u5019\u7528 throws\uff0c\u800c\u975e try-catch\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u5185\u591a\u5904\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\uff0c\u9010\u4e2a\u7f16\u5199<code>try-catch<\/code>\u4f1a\u8ba9\u4ee3\u7801\u81c3\u80bf\u3001\u53ef\u8bfb\u6027\u53d8\u5dee\u3002\u6b64\u65f6\u53ef\u4ee5\u7528<code>throws<\/code>\u5c06\u5f02\u5e38\u5411\u4e0a\u4f20\u9012\uff0c\u7edf\u4e00\u5728\u8c03\u7528\u65b9\u96c6\u4e2d\u5904\u7406\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001try-catch-finally \u5f02\u5e38\u6355\u83b7\u7ed3\u6784<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f Java \u6700\u6838\u5fc3\u7684\u5f02\u5e38\u5904\u7406\u8bed\u6cd5\uff0c\u7528\u6765<strong>\u6355\u83b7\u5e76\u5904\u7406\u5f02\u5e38<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. try \u5757<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u6765\u5305\u88f9<strong>\u53ef\u80fd\u51fa\u73b0\u5f02\u5e38\u7684\u4ee3\u7801<\/strong>\u3002\u5982\u679c\u4ee3\u7801\u6b63\u5e38\u6267\u884c\uff0c\u8d70\u5b8c<code>try<\/code>\u5757\uff1b\u4e00\u65e6\u51fa\u73b0\u5f02\u5e38\uff0c\u7acb\u523b\u7ec8\u6b62\u5f53\u524d\u884c\u540e\u7eed\u4ee3\u7801\uff0c\u8df3\u8f6c\u5230<code>catch<\/code>\u5757\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. catch \u5757<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u6765\u6355\u83b7<code>try<\/code>\u4e2d\u629b\u51fa\u7684\u5f02\u5e38\uff0c\u5e76\u7f16\u5199\u5904\u7406\u903b\u8f91\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e00\u4e2a<code>try<\/code>\u53ef\u4ee5\u642d\u914d\u591a\u4e2a<code>catch<\/code>\uff0c\u6355\u83b7\u4e0d\u540c\u7c7b\u578b\u5f02\u5e38\uff1b<\/li>\n\n\n\n<li><strong>\u591a\u4e2a catch \u5fc5\u987b\u9075\u5faa\uff1a\u5b50\u7c7b\u5f02\u5e38\u5728\u524d\uff0c\u7236\u7c7b\u5f02\u5e38\u5728\u540e<\/strong>\uff0c\u5426\u5219\u7f16\u8bd1\u62a5\u9519\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. finally \u5757<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u9009\u914d\u7f6e\uff0c<strong>\u65e0\u8bba try \u4e2d\u662f\u5426\u51fa\u73b0\u5f02\u5e38\uff0cfinally \u4ee3\u7801\u4e00\u5b9a\u4f1a\u6267\u884c<\/strong>\uff08\u7279\u6b8a\u60c5\u51b5\u9664\u5916\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6838\u5fc3\u7528\u9014\uff1a\u91ca\u653e\u8d44\u6e90\uff0c\u6bd4\u5982\u5173\u95ed\u6587\u4ef6\u6d41\u3001\u6570\u636e\u5e93\u8fde\u63a5\u3001\u7f51\u7edc\u8fde\u63a5\u7b49\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">finally \u4e0d\u4f1a\u6267\u884c\u7684\u7279\u6b8a\u573a\u666f<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4ee3\u7801\u8fdb\u5165\u6b7b\u5faa\u73af\uff1b<\/li>\n\n\n\n<li>\u6267\u884c <code>System.exit(0)<\/code> \u7ec8\u6b62 JVM\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b\uff1atry-catch-finally \u7efc\u5408\u4f7f\u7528<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TryCatchFinallyDemo {\n    public static void main(String&#91;] args) {\n        int num1 = 20;\n        int num2 = 0;\n\n        try {\n            System.out.println(\"\u5f00\u59cb\u6267\u884c\u8fd0\u7b97\");\n            int res = num1 \/ num2;\n            System.out.println(\"\u8fd0\u7b97\u7ed3\u679c\uff1a\" + res);\n        } catch (ArithmeticException e) {\n            \/\/ \u6355\u83b7\u7b97\u672f\u5f02\u5e38\u5e76\u5904\u7406\n            System.out.println(\"\u5f02\u5e38\u6355\u83b7\uff1a\u9664\u6570\u4e0d\u80fd\u4e3a0\uff01\");\n            e.printStackTrace();\n        } finally {\n            \/\/ \u8d44\u6e90\u91ca\u653e\/\u6536\u5c3e\u4ee3\u7801\uff0c\u5fc5\u5b9a\u6267\u884c\n            System.out.println(\"\u6267\u884cfinally\u4ee3\u7801\u5757\uff0c\u5b8c\u6210\u6536\u5c3e\u64cd\u4f5c\");\n        }\n        System.out.println(\"\u7a0b\u5e8f\u7ee7\u7eed\u5411\u4e0b\u8fd0\u884c\");\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u591a catch \u5199\u6cd5\u793a\u4f8b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class MultiCatchDemo {\n    public static void main(String&#91;] args) {\n        String str = null;\n        try {\n            str.length();\n        } catch (NullPointerException e) {\n            System.out.println(\"\u6355\u83b7\u7a7a\u6307\u9488\u5f02\u5e38\");\n        } catch (Exception e) {\n            \/\/ \u7236\u7c7b\u5f02\u5e38\u653e\u6700\u540e\n            System.out.println(\"\u6355\u83b7\u901a\u7528\u5f02\u5e38\");\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001Java \u5f02\u5e38\u5904\u7406\u6700\u4f73\u5b9e\u8df5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed3\u5408\u65e5\u5e38\u5f00\u53d1\u7ecf\u9a8c\uff0c\u5206\u4eab\u51e0\u70b9\u5b9e\u7528\u7684\u89c4\u8303\uff0c\u8ba9\u5f02\u5e38\u5904\u7406\u66f4\u4e13\u4e1a\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4f18\u5148\u6355\u83b7\u5177\u4f53\u5f02\u5e38<\/strong>\u4e0d\u8981\u76f4\u63a5\u6355\u83b7\u9876\u5c42<code>Exception<\/code>\uff0c\u4f1a\u63a9\u76d6\u771f\u5b9e\u9519\u8bef\uff0c\u4e0d\u5229\u4e8e\u95ee\u9898\u6392\u67e5\u3002\u80fd\u7cbe\u51c6\u6355\u83b7<code>NullPointerException<\/code>\u3001<code>IOException<\/code>\u5c31\u4e0d\u8981\u7528<code>Exception<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u4e0d\u968f\u610f\u6355\u83b7\u65e0\u6cd5\u5904\u7406\u7684\u5f02\u5e38<\/strong>\u5982\u679c\u5f53\u524d\u4e1a\u52a1\u903b\u8f91\u6ca1\u6709\u80fd\u529b\u4fee\u590d\u8be5\u5f02\u5e38\uff0c\u4e0d\u8981\u5f3a\u884c<code>catch<\/code>\uff0c\u4f7f\u7528<code>throws<\/code>\u5411\u4e0a\u629b\u51fa\uff0c\u4ea4\u7531\u4e0a\u5c42\u8c03\u7528\u65b9\u5904\u7406\u3002<\/li>\n\n\n\n<li><strong>\u8d44\u6e90\u91ca\u653e\u4ea4\u7ed9 finally<\/strong>IO \u6d41\u3001\u6570\u636e\u5e93\u8fde\u63a5\u7b49\u8d44\u6e90\uff0c\u52a1\u5fc5\u5728<code>finally<\/code>\u4e2d\u5173\u95ed\uff0c\u9632\u6b62\u8d44\u6e90\u6cc4\u6f0f\u3002<\/li>\n\n\n\n<li><strong>\u751f\u4ea7\u73af\u5883\u4f7f\u7528\u65e5\u5fd7\u8bb0\u5f55\u5f02\u5e38<\/strong>\u7ebf\u4e0a\u9879\u76ee\u4e0d\u8981\u53ea\u7528<code>e.printStackTrace()<\/code>\u6253\u5370\u63a7\u5236\u53f0\uff0c\u63a8\u8350\u4f7f\u7528\u65e5\u5fd7\u6846\u67b6\uff08SLF4J\u3001Logback \u7b49\uff09\u8bb0\u5f55\u5f02\u5e38\u5806\u6808\u3001\u4e0a\u4e0b\u6587\u4fe1\u606f\uff0c\u65b9\u4fbf\u7ebf\u4e0a\u6392\u9519\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u5199\u5728\u6700\u540e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f02\u5e38\u5904\u7406\u662f Java \u57fa\u7840\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u73af\uff0c\u4ece\u57fa\u7840\u7684\u6982\u5ff5\u533a\u5206\uff0c\u5230<code>try-catch-finally<\/code>\u3001<code>throw\/throws<\/code>\u7684\u4f7f\u7528\uff0c\u90fd\u662f\u65e5\u5e38\u7f16\u7801\u3001\u9762\u8bd5\u7684\u9ad8\u9891\u5185\u5bb9\u3002\u638c\u63e1\u597d\u5f02\u5e38\u673a\u5236\uff0c\u624d\u80fd\u5199\u51fa\u7a33\u5b9a\u3001\u5065\u58ee\u7684 Java \u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6700\u8fd1\u6574\u7406\u4e86 Java \u5f02\u5e38\u76f8\u5173\u7684\u77e5\u8bc6\u70b9\uff0c\u4eca\u5929\u7cfb\u7edf\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b Java \u7684\u5f02\u5e38\u5904\u7406\u673a\u5236\u3002\u5f02\u5e38\u662f\u5f00\u53d1\u4e2d<\/p>\n<div class=\"more-link\">\n\t\t\t\t <a href=\"https:\/\/yunyanglib.cn\/?p=1542\" class=\"link-btn theme-btn\"><span>Read More <\/span> <i class=\"fa fa-caret-right\"><\/i><\/a>\n\t\t\t<\/div>\n","protected":false},"author":1,"featured_media":1543,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[15],"class_list":["post-1542","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java"],"_links":{"self":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1542"}],"version-history":[{"count":3,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions"}],"predecessor-version":[{"id":1546,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1542\/revisions\/1546"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/media\/1543"}],"wp:attachment":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}