{"id":100301,"date":"2020-05-01T20:30:31","date_gmt":"2020-05-01T12:30:31","guid":{"rendered":"http:\/\/4563.org\/?p=100301"},"modified":"2020-05-01T20:30:31","modified_gmt":"2020-05-01T12:30:31","slug":"java-%e7%9a%84%e6%9c%89%e4%b8%aa%e5%bc%82%e5%b8%b8%e8%ae%be%e8%ae%a1%e4%b8%80%e7%9b%b4%e6%b2%a1%e7%90%86%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=100301","title":{"rendered":"Java \u7684\u6709\u4e2a\u5f02\u5e38\u8bbe\u8ba1\u4e00\u76f4\u6ca1\u7406\u89e3"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Java \u7684\u6709\u4e2a\u5f02\u5e38\u8bbe\u8ba1\u4e00\u76f4\u6ca1\u7406\u89e3               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : matepi <\/span>  <span><i><\/i> 58<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u7c7b\u4f3c<\/p>\n<pre><code>  int i = Integer.parseInt(\"e\"); \u4f1a\u629b\u51fa   java.lang.NumberFormatException <\/code><\/pre>\n<pre><code>  NumberFormatException \u7684\u96b6\u5c5e\u5173\u7cfb Object   -Throwable     -Exception       -RuntimeException         -IllegalArgumentExcetipn           -NumberFormatException <\/code><\/pre>\n<p>\u633a\u6b63\u5e38\uff0c\u6355\u83b7 Exception \u5c31\u80fd catch \u4f4f\u4ed6<\/p>\n<p>\u7136\u800c\u5982\u679c\u8fd9\u4e48\u5199<\/p>\n<pre><code>  static int i = Integer.parseInt(\"e\"); \u4f1a\u629b\u51fa   java.lang.ExceptionInitializerError ..  Caused by: java.lang.NumberFormatException ... <\/code><\/pre>\n<pre><code>\u800c ExceptionInitializerError \u7684\u7684\u96b6\u5c5e\u5173\u7cfb Object   -Throwable     -Error       -LinkageError         -ExceptionInitializerError <\/code><\/pre>\n<p>\u8fd9\u65f6\uff0c\u6355\u83b7 Exception \u5df2\u7ecf\u4e0d\u80fd catch \u4f4f\u8fd9\u4e2a\u5f02\u5e38\u4e86\u3002\u9700\u8981\u6355\u83b7 Throwable \u6216\u8005 Exception | Error \u4e86\u3002<\/p>\n<p>\u7136\u800c\u540c\u6837\u90fd\u662f\u505a\u4e86\u4e00\u4e2a<code>Integer.parseInt(\"e\")<\/code>\uff0c\u8fd9\u65f6\u5347\u683c\u6210\u4e3a static\uff0c\u5c31\u9020\u6210\u4e86\u5f02\u5e38\u7c7b\u7684\u53d8\u5316\u3002\u5bfc\u81f4\u6355\u83b7\u65b9\u5f0f\u7684\u53d8\u5316\u3002\u8fd9\u662f\u4e0d\u662f\u5f88\u5947\u602a\uff1f<\/p>\n<p>\u5f53\u7136\u8fd9\u91cc\u7684<code>Integer.parseInt(\"e\")<\/code>\uff0c\u53ea\u662f\u4e00\u4e2a\u4f8b\u5b50 \u5982\u679c\u4f60\u6709\u4f60\u53ef\u7231\u7684\u540c\u5b66\uff0c\u5728 static \u5757 \/\u53d8\u91cf\u91cc\u9762\u5199\u4e86\u4e00\u5927\u6bb5\u590d\u6742\u903b\u8f91\uff0c\u641e\u51fa\u5404\u79cd\u5404\u6837\u7684 Exception\uff0c\u90fd\u4f1a\u88ab\u5347\u683c\u6210\u4e3a<code>ExceptionInitializerError<\/code>\u3002\u4ece\u800c\u4e0d\u80fd\u88ab catch Exception \u6240 catch<\/p>\n<p>\u4ece\u7c7b\u7684\u521d\u59cb\u5316\u8fc7\u7a0b\u3001\u4ece\u7f16\u8bd1\u7684\u89d2\u5ea6\u8c8c\u4f3c\u80fd\u591f\u7406\u89e3\u8fd9\u4e2a LinkageError\u3002\u4f46\u4ece\u5177\u4f53\u903b\u8f91\u7684\u89d2\u5ea6\uff0c\u8fd9\u4e3a\u5565\u5462\uff1f<\/p>\n<p>\u5176\u5b9e\u8fd9\u4e2a\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\u6709\u4eba\u8bf4\u5230\u7684\u6240\u8c13\u7684\u5f02\u5e38\u5904\u7406&#8221;\u519b\u89c4&#8221;\uff0cNever catch Throwable class\u3002\u8fd9\u70b9\u5728\u8fd9\u4e2a\u60c5\u51b5\u4e0b\u53c8\u5982\u4f55\u7406\u89e3\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>26<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"777471\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : darrenfang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u6837\u5199\u5e76\u4e0d\u4f1a\u6709\u95ee\u9898<\/p>\n<p>&#8220;`java<br \/> static int i;<\/p>\n<p> static {<br \/> try {<br \/> i = Integer.parseInt(&#8220;e&#8221;);<br \/> } catch (Exception e) {<br \/> }<br \/> }<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777472\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SpencerCJH <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b66\u5230\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777473\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : watzds <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u975e\u5e38\u6b63\u5e38\u597d\u5427\uff0c\u89e3\u6790\u5931\u8d25\uff0ci \u6ca1\u6709\u503c\uff0c\u521d\u59cb\u5316 i \u5931\u8d25\uff0c\u662f\u4e24\u79cd\u9519\u8bef                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777474\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : passerbytiny <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u53ef\u4ee5<br \/>`try{<br \/>` int i = Integer.parseInt(&#8220;e&#8221;);<br \/>`}catch &#8230;<br \/>\u4f46\u4e0d\u53ef\u4ee5<br \/>`try{<br \/>` static int i = Integer.parseInt(&#8220;e&#8221;);<br \/>`}catch &#8230;<\/p>\n<p>\u6240\u4ee5\u524d\u8005\u629b\u51fa\u5f02\u5e38\uff0c\u540e\u8005\u629b\u51fa\u9519\u8bef\u3002Exception\u3001Error \u867d\u7136\u90fd\u7ee7\u627f\u81ea Throwable\uff0c\u4f46\u539f\u5219\u4e0a\u524d\u8005\u6355\u83b7\u540e\u5141\u8bb8\u5904\u7406\u4f7f\u5176\u6d88\u5931\uff0c\u540e\u8005\u6355\u83b7\u540e\u53ea\u80fd\u505a\u65e5\u5fd7\u3001\u544a\u8b66\u800c\u4e0d\u80fd\u5904\u7406\u2014\u2014\u5fc5\u987b\u4e2d\u65ad\u7a0b\u5e8f\u6216\u8005 5**\u8fd4\u56de\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777475\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : palmers <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u540c\u610f 3#\u7684\u8bf4\u6cd5 \u4e24\u79cd\u5f02\u5e38\u4e00\u79cd\u662f\u89e3\u6790\u5931\u8d25\u5f02\u5e38\u4e00\u79cd\u662f\u521d\u59cb\u5316\u5931\u8d25\u5f02\u5e38\uff0c \u53ea\u4e0d\u8fc7\u540e\u9762\u53c8\u7ed9\u5305\u88c5\u4e86\u4e00\u4e0b \u5c31\u50cf\u6211\u4eec\u5e38\u5e38\u5c06 api \u7684\u5f02\u5e38\u5305\u88c5\u4e3a\u81ea\u5df1\u7684\u4e1a\u52a1\u5f02\u5e38\u4e00\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777476\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lff0305 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ExceptionInitializerError \u521d\u59cb\u5316\u5f02\u5e38, \u8868\u793a\u521d\u59cb\u5316\u8fd9\u4e2a\u7c7b\u7684\u65f6\u5019\u51fa\u9519\u4e86\uff0c\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u51fa\u9519\uff0c\u5177\u4f53\u539f\u56e0\u662f NumberFormatException, \u5728 getCause() \u91cc\u9762                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777477\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : matepi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @darrenfang @passerbytiny \u6709\u7684\u65f6\u5019\uff0c\u6211\u4eec\u662f\u9762\u5411\u522b\u4eba\u7684\u4ee3\u7801\u7f16\u7a0b\u2026\u2026\u4f60\u5f15\u5165\u4e86\u4e00\u4e2a\u5305\uff0c\u751a\u81f3\u90fd\u6ca1\u6709\u6e90\u7801\u7684\u60c5\u51b5\u4e0b\u3002\u5e76\u4e0d\u77e5\u9053\u53ef\u7231\u7684\u524d\u4efb\u7ed9\u4f60\u7559\u4e86\u4e2a\u8fd9\u6837\u7684\u5751\u3002<br \/>\u8bf4\u771f\u7684\uff0c\u7c7b\u4f3c\u8fd9\u79cd\u521d\u59cb\u8fc7\u7a0b\u4e2d\u5f02\u5e38\u6027\u6ca1\u5b8c\u5168\u5305\u597d\u7684\u4e8b\u60c5\uff0c\u5176\u5b9e\u662f\u5f88\u591a\u7684\uff0c\u5373\u4fbf\u8d28\u91cf\u6bd4\u8f83\u597d\u7684\u6846\u67b6\u6709\u65f6\u5019\u4e5f\u4f1a\u548c\u4e00\u4e9b\u73af\u5883\u914d\u7f6e\u4e0a\u641e\u51fa\u8fd9\u6837\u7684\u4e8b\u60c5\u3002\u6700\u7ec8\u8fd8\u4f1a\u51fa\u4e00\u4e9b\u7c7b\u4f3c\u7c7b\u660e\u660e\u5728\uff0c\u7136\u540e NoClassDefFound \u7684\u5f02\u5e38\u3002\u53c8\u7c7b\u4f3c headless \u90a3\u79cd\u73af\u5883\u6027\u914d\u7f6e\u3002<\/p>\n<p>@palmers \u5982\u679c\u6709\u8bbe\u8ba1\u7684\u5305\u88c5\u8fd9\u4e2a\u662f\u53ef\u4ee5\u7406\u89e3\u7684\u3002\u4f46\u95ee\u9898\u5c31\u5728\u4e8e\u8fd9\u4e2a\u5305\u88c5\u5e76\u4e0d\u662f\u4f60\u8bbe\u8ba1\u7684\u3002\u4e5f\u4e0d\u662f\u524d\u4eba\u8bbe\u8ba1\u7684\u3002\u662f\u67d0\u79cd\u5f02\u5e38\u73af\u5883\u914d\u7f6e\u4e0b\u624d\u4f1a\u51fa\u73b0\u7684\u5c1a\u672a\u8bbe\u8ba1\u7684\u4e8b\u60c5\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777478\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iFlicker <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u56f0\u60d1\u7684\u662f\u4e3a\u4ec0\u4e48\u5728\u7528 static \u4fee\u9970 \u53d8\u91cf \u7684\u65f6\u5019\u4f1a\u6355\u83b7 ExceptionInitializerError \u5462\uff1f<br \/>\u5177\u4f53\u662f\u5728\u7f16\u8bd1\u8fc7\u7a0b\u7684\u8bcd\u6cd5\u5206\u6790\u5417\uff1f \u6709\u6ca1\u6709\u5927\u4f6c\u89e3\u7b54\u4e00\u4e0b~                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777479\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chendy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9759\u6001\u53d8\u91cf\u8981\u521d\u59cb\u5316\uff0c\u9759\u6001\u53d8\u91cf\u521d\u59cb\u5316\u4e0d\u4e86\u7c7b\u52a0\u8f7d\u4f1a\u6709\u95ee\u9898\uff0c\u7c7b\u52a0\u8f7d\u6709\u95ee\u9898\u7c7b\u5c31\u7528\u4e0d\u4e86\uff0c\u7c7b\u90fd\u7528\u4e0d\u4e86\u4ee3\u7801\u5c31\u8dd1\u4e0d\u8d77\u6765\u4e5f\u5c31\u4e0d\u7528\u8003\u8651\u53bb catch \u4e86\uff0ccatch \u4f4f\u4e86\u4e5f\u6ca1\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777480\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : momocraft <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             static \u53d8\u91cf\u7684\u6c42\u503c\u53d1\u751f\u5728 class load \u65f6?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777481\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iFlicker <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @iFlicker \u7406\u987a\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777482\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : szq8014 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u662f\u540c\u4e00\u4e2a\u5f02\u5e38\uff0c\u90fd\u662f NumberFormatException \uff0c\u53ea\u4e0d\u8fc7\u540e\u9762\u90a3\u4e2a\u53c8\u7ed9\u5305\u88c5\u4e86\u4e00\u5c42\uff0c\u76f4\u63a5\u6362\u6210 error \u6254\u51fa\u6765\u4e86\uff0c\u6bd5\u7adf\u662f static \u7684\u53d1\u751f\u5728\u7c7b\u52a0\u8f7d\u671f\uff0c\u521d\u59cb\u5316\u5931\u8d25\u5f53\u7136\u4e0d\u80fd\u7ee7\u7eed\u8fd0\u884c\u4e86\uff0c\u629b\u4e2a Error \u662f\u53ef\u671f\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777483\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shily <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @iFlicker <br \/>@lff0305 # 6 \u7684\u624d\u662f\u6b63\u786e\u7b54\u6848\u3002<\/p>\n<p>\u300e\u90fd\u4f1a\u88ab\u5347\u683c\u6210\u4e3a ExceptionInitializerError\u3002\u4ece\u800c\u4e0d\u80fd\u88ab catch Exception \u6240 catch \u300f\u8fd9\u4e2a\u8bf4\u6cd5\u672c\u8eab\u662f\u9519\u8bef\u7684\u3002<br \/>\u5443\uff0c\u600e\u4e48\u8bf4\u5462\uff0c\u5b83\u5e76\u4e0d\u662f\u88ab\u5347\u683c\uff0c\u800c\u662f\u56e0\u4e3a\u4f60\u4e0d\u5904\u7406\uff0c\u5bfc\u81f4 JVM \u65e0\u6cd5\u8fdb\u884c\u4e0b\u53bb\uff0cJVM \u5d29\u6e83\u4e86\uff0c\u4e3a\u4e86\u8fdb\u4e00\u6b65\u8868\u793a JVM \u4e3a\u4ec0\u4e48\u5d29\u6e83\u800c\u5305\u88c5\u4e86\u4e00\u4e0b\u3002<\/p>\n<p>ExceptionInitializerError \u8868\u793a\u7c7b\u521d\u59cb\u5316\u7684\u65f6\u5019\u53d1\u751f\u4e86\u5f02\u5e38\uff0c\u53ef\u4ee5\u901a\u8fc7 getCause() \u83b7\u77e5\u9519\u8bef\u7684\u5177\u4f53\u539f\u56e0\u3002<\/p>\n<p>\u5450\u5982\u679c\u6211\u60f3\u81ea\u5df1\u5904\u7406 NumberFormatException \u6539\u600e\u4e48\u5199\u5462\uff1f<\/p>\n<p> static int i = Integer.parseInt(&#8220;e&#8221;); \/\/ \u65e0\u6cd5\u76f4\u63a5\u4f7f\u7528 try-catch<\/p>\n<p>\u4f46\u662f\u5b83\u7b49\u4ef7\u4e8e<\/p>\n<p> static int i;<br \/> static {<br \/> i = Integer.parseInt(&#8220;e&#8221;);<br \/> }<\/p>\n<p>\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u81ea\u884c\u5904\u7406\u5176\u4e2d\u629b\u51fa\u7684\u5f02\u5e38\u4e86\u3002<br \/> static int i;<br \/> static {<br \/> try {<br \/> i = Integer.parseInt(&#8220;e&#8221;);<br \/> } catch (NumberFormatException nfe) {<br \/> \/\/ handle exception here<br \/> }<br \/> }                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777484\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : passerbytiny <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @matepi #7 \u5148\u8bb2\u6280\u672f\uff0c\u518d\u627e\u7406\u7531\u3002<\/p>\n<p>int i = Integer.parseInt(some \u53d8\u91cf\uff09\u624d\u6709\u53ef\u80fd\u51fa\u73b0\u5f02\u5e38\uff0c\u800c\u5728\u975e\u6f14\u793a\u76ee\u7684\u7684\u60c5\u51b5\u4e0b\u5199\u51fa\u6765 int i = Integer.parseInt(&#8220;e&#8221;)\u8fd9\u6837\u7684\u4ee3\u7801\u5c31\u662f\u6c99\u96d5\uff0c\u6240\u4ee5\u6b64\u65f6\u629b\u51fa\u7684\u662f\u8fd0\u884c\u65f6\u5f02\u5e38\u2014\u2014\u4f60\u65e0\u6cd5\u907f\u514d\u5b83\u4f46\u662f\u53ef\u4ee5\u89e3\u51b3\u5b83\u3002<br \/>static int i = Integer.parseInt(&#8220;e&#8221;)\u8fd9\u660e\u663e\u662f\u6c99\u96d5\u4ee3\u7801\uff1b static String someIntStr = &#8220;e&#8221;; static int i = Integer.parseInt( someIntStr )\u4ecd\u7136\u662f\u6c99\u96d5\u4ee3\u7801\uff1b static int i; void initOrUpdate(String aIntStrForInit){ if(Class.i == -1){ Class.i = Integer.parseInt(aIntStrForInit)} }\u4f1a\u629b\u51fa NumberFormatException\uff1a\u6240\u4ee5\u6b64\u65f6\u524d\u4e24\u79cd\u60c5\u51b5\u629b\u51fa\u7684\u662f\u9519\u8bef\u2014\u2014\u4f60\u4e0d\u80fd\u89e3\u51b3\u5b83\u800c\u53ea\u80fd\u4fee\u6539\u6e90\u4ee3\u7801\u533a\u907f\u514d\u5b83<\/p>\n<p>\u6280\u672f\u4e0a\u6765\u8bf4\uff1a<br \/>\u4e00\uff0c\u6846\u67b6\u6216\u8005\u5e93\uff0c\u4e0d\u7ba1\u662f\u6c99\u96d5\u8fd8\u662f\u6ca1\u8003\u8651\u5230\u800c\u53d1\u751f\u4e86\u81f4\u547d\u9519\u8bef\uff0c\u5c31\u8be5\u7ed9\u5bf9\u65b9\u629b\u51fa\u4e2a java.lang.Error\uff0c\u544a\u8bc9\u5bf9\u65b9\u8fd9\u73a9\u610f\u4f60\u522b\u89e3\u51b3\u4e86\uff0c\u7b49\u6211\u89e3\u51b3\u6216\u8005\u7528\u5176\u5b83\u5e93\u3002\u800c\u4e0d\u80fd\u662f\u629b\u51fa\u4e2a java.lang.Exception \u6216\u8005 java.lang.RuntimeException\uff0c\u544a\u8bc9\u5bf9\u65b9\u8fd9\u73a9\u610f\u4f60\u81ea\u884c\u89e3\u51b3\u6216\u8005\u4e0d\u4e88\u7406\u4f1a\u3002\u4f5c\u4e3a\u5bf9\u65b9\uff0c\u4f60\u5e94\u8be5\u611f\u8c22\u5bf9\u65b9\u629b\u4e86 Error \u901a\u77e5\u4f60\uff0c\u800c\u4e0d\u662f\u629b\u4e2a Exception \u63a9\u76d6\u81f4\u547d\u9519\u8bef\u3002<br \/>\u4e8c\uff0c\u524d\u4eba\u7684\u4ee3\u7801\uff0c\u4e0d\u7ba1\u662f\u6c99\u96d5\u3001\u4e0d\u60f3\u5e72\uff0c\u8fd8\u662f\u4ec0\u4e48\u4e71\u8d77\u516b\u7cdf\u7684\u539f\u56e0\uff0c\u53d1\u751f\u81f4\u547d\u9519\u8bef\u7684\u65f6\u5019\uff0c\u5c31\u8be5\u7ed9\u540e\u4eba\u629b\u51fa\u4e2a java.lang.Error\uff0c\u544a\u8bc9\u540e\u4eba\u8fd9\u73a9\u610f\u4f60\u522b\u60f3\u5728\u4f60\u81ea\u5df1\u7684\u4ee3\u7801\u4e2d\u89e3\u51b3\u4e86\uff0c\u91cd\u6784\u6211\u7ed9\u4f60\u7559\u7684\u4ee3\u7801\u6216\u8005\u5411\u4e0a\u7ea7\u6482\u6311\u5b50\u5427\u3002\u4f5c\u4e3a\u540e\u4eba\uff0c\u4f60\u5e94\u8be5\u611f\u8c22\u524d\u4eba\u597d\u5fc3\u63d0\u9192\u4f60\uff0c\u800c\u4e0d\u662f\u5f04\u4e2a Exception \u7ee7\u7eed\u7cca\u5f04\u4f60\u3002<\/p>\n<p>\u6280\u672f\u4e0a\u6765\u8bf4\u8fd8\u53ef\u4ee5\u7b80\u5355\u7684\u4e00\u53e5\u8bdd\uff1a\u5751\u5c31\u5728\u90a3\u91cc\uff0c\u4f60\u8981\u8fc7\u53bb\u5c31\u5fc5\u987b\u586b\u5751\uff1b\u4f60\u628a Error \u6362\u6210 Exception \u5e76\u4e0d\u80fd\u586b\u5751\uff0c\u53cd\u800c\u8ba9\u4f60\u6389\u8fdb\u53bb\u3002<\/p>\n<p>\u4ee5\u4e0a\u5927\u6982\u80fd\u89e3\u51b3\u4f60\u5bf9\u201cNever catch Throwable class\u201d\u7684\u7591\u95ee\u3002<\/p>\n<p>\u4e0b\u9762\u6765\u8bf4 static int i = Integer.parseInt(&#8220;e&#8221;);\u629b\u51fa Error\u3002<\/p>\n<p>\u9759\u6001\u53d8\u91cf\u4e0d\u662f new \u5bf9\u8c61\u7684\u65f6\u5019\u7531 ClassLoader \u8bbe\u503c\u7684\uff0c\u800c\u662f JVM \u770b\u5230\u5b83\u7684\u65f6\u5019\u7531 JVM \u8bbe\u503c\u7684\uff0c\u6b64\u65f6\u8981\u662f\u65e0\u6cd5\u8bbe\u503c\uff0c\u90a3\u5c31\u662f JVM \u7ea7\u522b\u7684\u81f4\u547d\u9519\u8bef\u3002\u4f60\u5c31\u7b97\u4e0d\u8003\u8651\u5e95\u5c42\u5b9e\u73b0\uff0c\u5728\u4e0a\u5c42\u4e0a\u770b\uff0c\u7ed9\u9759\u6001\u503c\u8bbe\u7f6e\u503c\u5374\u8bbe\u4e0d\u4e0a\u53bb\uff0c\u5c31\u50cf\u7ed9\u4eba\u53d6\u540d\u53eb\u5f20\u4e09\u4f46\u201c\u5f20\u4e09\u201d\u8fd9\u4e24\u4e2a\u5b57\u6709\u813e\u6c14\u4e00\u6837\uff0c\u662f\u81f4\u547d\u9519\u8bef\u3002static SomeType someVariable = {\u4e00\u6bb5\u6709\u53ef\u80fd\u51fa\u9519\u7684\u4ee3\u7801}\uff0c\u8fd9\u662f\u5f88\u5371\u9669\u7684\u884c\u4e3a\uff0c\u629b\u51fa Error \u4e0d\u8db3\u4e3a\u602a\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777485\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : passerbytiny <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @shily #13 \u4f60\u8fd9\u4e2a\u5bf9\u4e3b\u6765\u8bf4\u4e0d\u89e3\u51b3\u95ee\u9898\uff0c\u4e3b\u5927\u6982\u662f\u5728\u6700\u5916\u5c42\u6709\u4e00\u4e2a\u7edf\u4e00\u7684\u5f02\u5e38\u5904\u7406\uff0c\u5e76\u4e0d\u60f3\u5728\u629b\u5f02\u5e38 \/\u9519\u8bef\u7684\u5730\u65b9\u8fdb\u884c\u89e3\u51b3\u3002\u4ed6\u5927\u6982\u7387\u4f1a\u5199\u6210\u8fd9\u6837\uff1a<br \/> static int i;<br \/> static {<br \/> try {<br \/> i = Integer.parseInt(&#8220;e&#8221;);<br \/> } catch (NumberFormatException nfe) {<br \/> throw new Exception(nfe);<br \/> }<br \/> }<\/p>\n<p>\u7136\u540e\u7f16\u8bd1\u90fd\u8fc7\u4e0d\u53bb\uff0c\u56de\u8fc7\u5934\u6765\u518d\u8868\u8fbe\u201c\u6211\u5f88\u82e6\u201d\u3002<\/p>\n<p>@iFlicker #8 \u539f\u5219\u4e0a\u662f\u4e0d\u80fd\u6355\u83b7 Error \u7684\uff0c\u4ed6\u5e94\u8be5\u662f\u5728\u6700\u4e0a\u5c42\u6355\u83b7\u4e86 Throwable\uff0c\u6216\u8005\u4e0d\u662f\u6355\u83b7\u5230\u800c\u662f\u7a0b\u5e8f\u4e2d\u65ad\u540e\u5728\u65e5\u5fd7\u4e2d\u770b\u5230\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777486\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dallaslu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             V2EX \u7684\u8bc4\u8bba\u91cc\u5230\u5e95\u80fd\u4e0d\u80fd\u7528 markdown \u5440\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777487\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : matepi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @passerbytiny \u4e0d\uff0c\u5e76\u4e0d\u4f1a\u662f\u60f3\u5728\u5916\u5c42\u89e3\u51b3\u3002\u8fd9\u4e2a\u95ee\u9898\u4e4b\u6240\u4ee5\u63d0\uff0c\u662f\u5c31\u662f\u56e0\u4e3a\u8fd9\u662f\u6ca1\u6cd5\u5f88\u597d\u5728\u5916\u5c42\u89e3\u51b3\u7684\u3002\u5fc5\u987b\u6539\u5185\u5c42\u4ed6\u4eba\u4ee3\u7801\u7684\u201c\u7a7f\u5c42\u201d\u7684\u95ee\u9898\u3002<br \/>\u6709\u95ee\u9898\u80fd\u67e5\u5c31\u884c\uff0c\u8fd9\u79cd\u5f02\u5e38\u9ebb\u70e6\u5c31\u52a0\u4e4b\u5927\u5bb6\u90fd\u4e0d\u6355\u83b7 exception \u4ee5\u5916\u7684 throwable \u6765\u8bb0\u65e5\u5fd7\u3002<br \/>\u8fd9\u4e2a parse&#8221;e&#8221;\u53ea\u662f\u4e2a\u7b80\u5199\u4f8b\u5b50\uff0c\u4e0d\u662f\u771f\u50bb\u4ee3\u7801\u3002\u771f\u60c5\u51b5\u662f\u73af\u5883\u4e0a\u9047\u5230\u8fc7 parseInt \u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u91cc\u9762\u8bfb\u4e0a\u6765\u7684\u5b57\u7b26\u4e32\u3002\u7136\u540e\u914d\u7f6e\u5b57\u7b26\u4e32\u8be5\u5199\u6570\u5b57 0 \u7684\uff0c\u5199\u4e86\u4e2a\u5b57\u6bcd O\u3002\u7136\u540e\u89e3\u6790\u5931\u8d25\u3002error \u5f02\u5e38\u4e00\u8def\u8dd1\u5230\u6700\u5916\u5c42\uff0c\u6700\u5916\u5c42\u7684 logger \u53ea\u6355\u83b7 exception\u3002\u6ca1\u6709\u9ed8\u8ba4 err \u7684 log\uff0c\u5f02\u5e38\u5728\u6240\u6709\u7684\u65e5\u5fd7\u91cc\u90fd\u6ca1\u6709\u3002\u7ed3\u679c\u8fd9\u4e2a\u95ee\u9898\u5c31\u53d8\u5f97\u5f02\u5e38\u7684\u96be\u67e5\u660e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777488\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lazyfighter <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7406\u89e3\u4e00\u4e0b error \u548c exception \u6211\u611f\u89c9\u5c31\u53ef\u4ee5\u660e\u767d\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777489\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : matepi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u5927\u5bb6\u8981\u5199\u7c7b\u4f3c\u5728\u521d\u59cb\u5316\u4e2d\u7684\u4ee3\u7801<br \/>\u9996\u5148\u8fd8\u662f\u63a8\u8350\u5927\u5bb6\u641e\u5de5\u5382\u5355\u4f8b<\/p>\n<p>\u518d\u4e0d\u6d4e\u76f4\u63a5\u518d\u7c7b\u6784\u9020\u91cc\u9762\u5199\u4e2a static \u53d8\u91cf\u5224 null\uff0c\u6216\u5224\u9ed8\u8ba4-1 \u4e4b\u7c7b\u7684\uff0c\u518d\u8bfb\u53d6\u4e4b\u7c7b<br \/>if (svar == -1) svar = readAndParseIntFromProp(&#8230;);<br \/>\u90fd\u6bd4<br \/>\u76f4\u63a5\u7684<br \/>static int svar = readAndParseIntFromProp(&#8230;);<br \/>\u8981\u5c11\u70b9\u5751                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777490\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @matepi \u6211\u7ecf\u5e38 catch throwable\uff0c\u56e0\u4e3a\u67d0\u4e9b\u573a\u666f\u4e0b\uff0c\u752d\u7ba1\u4ec0\u4e48\u539f\u56e0\u5931\u8d25\u7684\uff0c\u6211\u53ef\u4ee5 fallback\uff0cfallback \u5931\u8d25\u518d\u964d\u7ea7\u4f7f\u7528\u3002catch throwable \u4e0d\u662f\u6d2a\u6c34\u731b\u517d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777491\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Raymon111111 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u629b\u51fa\u6765\u5305\u88c5\u4e86\u4e00\u4e0b<\/p>\n<p>\u8bd5\u60f3\u4f60\u5199\u4e00\u4e2a\u83b7\u53d6\u7528\u6237\u7684\u63a5\u53e3\uff0c\u7ed3\u679c\u6570\u636e\u5e93\u62a5\u4e86\u4e2a\u6570\u636e\u5e93\u76f8\u5173\u7684\u9519\u8bef\uff0c\u4f60\u80af\u5b9a\u5f97\u8f6c\u4e00\u4e0b\u554a                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777492\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : restlessdream <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Java \u7684 Error \u7c7b doc \u7b2c\u4e00\u53e5\u5c31\u662f\uff1a<br \/> An {@code Error} is a subclass of {@code Throwable} that indicates serious problems that a reasonable application<br \/> should not try to catch. Most such errors are abnormal conditions.<\/p>\n<p>\u5982\u679c\u51fa\u73b0 Error \u7684\u5f02\u5e38\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u8868\u660e\u662f\u4e25\u91cd\u9519\u8bef\uff0c\u5fc5\u987b\u8981\u8fdb\u884c\u89e3\u51b3\uff0c\u800c\u4e0d\u662f\u901a\u8fc7 catch \u6765\u5ffd\u7565\u6389\uff0c\u4e0a\u9762\u5f88\u591a\u4eba\u8bf4\u4e86\uff0c\u7c7b\u52a0\u8f7d\u671f\u95f4\u51fa\u73b0\u5f02\u5e38\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7c7b\u5c31\u662f\u4e0d\u53ef\u7528\u7684\uff0c\u8fd9\u4e2a\u65f6\u5019\u9700\u8981\u53bb\u89e3\u51b3\u4ee3\u7801 bug\uff0c\u800c\u4e0d\u662f\u53bb catch \u6765\u5ffd\u7565\u6389\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777493\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : matepi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @restlessdream \u6ca1\u8bf4\u6293\u4e86\u5ffd\u7565\u6389\u4e0d\u89e3\u51b3\u2026\u2026\u8bf4\u7684\u662f\u7531\u4e8e\u6709\u4eba\u771f\u53bb\u4fe1\u4e86 Never catch Throwable class\uff0c\u9020\u6210\u5f02\u5e38\u4e00\u8def\u5230\u4e86\u6700\u5916\u5c42\uff0c\u90fd\u6ca1\u4eba\u6293\u3002\u5bfc\u81f4\u65e5\u5fd7\u91cc\u90fd\u627e\u4e0d\u5230 Error \u7684\u5f02\u5e38\u3002\u5bfc\u81f4 bug \u7684\u96be\u4ee5\u5b9a\u4f4d\u89e3\u51b3\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777494\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chendy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u201c\u6211\u540c\u6837\u8981\u89e3\u51b3\u7684\u662f\u201c\u6293\u5230\u201d\u8fd9\u4e2a\u5f02\u5e38\u4e4b\u540e\u4fee\u6b63\u3002\u201c<br \/>\u4e0d\u77e5\u9053\u4ec0\u4e48\u7c7b\u578b\u7684\u9879\u76ee\uff0c\u5982\u679c\u662f crud \u7c7b\u7684\u5168\u5c40\u6293 Throwable \u6253 log \u770b\u4e00\u773c stack trace \u5c31\u80fd\u6293\uff0c\u7136\u540e\u6539\u4fee\u4fee\u6539\u7529\u9505\u7529\u9505\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777495\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : matepi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chendy \u4e0d\u4f1a\u6293 Throwable\uff0c\u53ea\u4f1a\u6293 Exception\uff0c\u662f\u5f88\u591a\u4eba\u7684\u4e60\u60ef\u3002\u76f8\u4fe1\u8fd9\u91cc\u9762\u90fd\u6709\u8d85\u8fc7\u4e00\u534a\u90fd\u662f\u3002\u4e14\u5e0c\u671b\u5199\u5168\u5c40\u7684\u4eba\u77e5\u9053\u6293 Throwable \u5427\u3002\u66f4\u591a\u65f6\u5019\u53ea\u80fd\u5728\u81ea\u5df1\u7684\u4ee3\u7801\u51fa\u53e3\u4e0a\u6293\u4e2a Throwable\uff0c\u8bb0\u4e0b\u65e5\u5fd7\uff0c\u7136\u540e\u7ee7\u7eed throw\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"777496\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mxalbert1996 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u91cc never catch \u7684 catch \u6307\u7684\u662f\u72ed\u4e49\u7684 catch\uff0c\u5373 catch \u540e\u541e\u6389\uff0c\u5148 catch \u5199\u4e86\u65e5\u5fd7\u4ee5\u540e\u518d throw \u7b97 rethrow \u5427\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Java \u7684\u6709\u4e2a\u5f02\u5e38\u8bbe\u8ba1\u4e00\u76f4\u6ca1\u7406\u89e3&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/100301"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100301"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/100301\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100301"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}