\n \u4e3b\u8981\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u5f02\u5e38: \u9009\u4e2d\u548c\u672a\u9009\u4e2d\u3002\u5728\u8fd9\u91cc\uff0c\u9519\u8bef\u88ab\u89c6\u4e3a\u672a\u68c0\u67e5\u7684\u5f02\u5e38\u3002\u6839\u636eOracle\u7684\u4ecb\u7ecd\uff0c\u5b58\u5728\u4e09\u79cd\u7c7b\u578b\u7684\u5f02\u5e38:\n <\/div>\n
\u5df2\u68c0\u67e5\u7684\u5f02\u5e38<\/span>
\n \u672a\u7ecf\u68c0\u67e5\u7684\u5f02\u5e38<\/span>
\n \u9519\u8bef<\/span>
\n
<\/p>\n\u5df2\u68c0\u67e5\u548c\u672a\u68c0\u67e5\u7684\u5f02\u5e38\u4e4b\u95f4\u7684\u533a\u522b<\/h2>\n 1)\u5df2\u68c0\u67e5\u7684\u5f02\u5e38<\/h3>\n\n \u76f4\u63a5\u7ee7\u627fThrowable\u7c7b(\u9664RuntimeException\u548cError\u5916)\u7684\u7c7b\u79f0\u4e3a\u5df2\u68c0\u67e5\u7684\u5f02\u5e38\uff0c\u4f8b\u5982IOException\uff0cSQLException\u7b49\u3002\u5728\u7f16\u8bd1\u65f6\u68c0\u67e5\u5df2\u68c0\u67e5\u7684\u5f02\u5e38\u3002\n <\/div>\n
2)\u672a\u68c0\u67e5\u7684\u5f02\u5e38<\/h3>\n\n \u7ee7\u627fRuntimeException\u7684\u7c7b\u79f0\u4e3a\u672a\u7ecf\u68c0\u67e5\u7684\u5f02\u5e38\uff0c\u4f8b\u5982ArithmeticException\uff0cNullPointerException\uff0cArrayIndexOutOfBoundsException\u7b49\u3002\u672a\u7ecf\u68c0\u67e5\u7684\u5f02\u5e38\u4e0d\u5728\u7f16\u8bd1\u65f6\u68c0\u67e5\uff0c\u4f46\u5728\u8fd0\u884c\u65f6\u68c0\u67e5\u3002\n <\/div>\n
3)\u9519\u8bef<\/h3>\n\n \u9519\u8bef\u662f\u65e0\u6cd5\u6062\u590d\u7684\uff0c\u4f8b\u5982OutOfMemoryError\uff0cVirtualMachineError\uff0cAssertionError\u7b49\u3002\n <\/div>\n
\n
Java\u5f02\u5e38\u5173\u952e\u5b57<\/h2>\n\n \u67095\u4e2a\u5173\u952e\u5b57\u7528\u4e8e\u5904\u7406Java\u4e2d\u7684\u5f02\u5e38\u3002\n <\/div>\n
\n\n\n\u5173\u952e\u5b57<\/td>\n | \u8bf4\u660e<\/td>\n<\/tr>\n |
\ntry<\/td>\n | \"try\"\u5173\u952e\u5b57\u7528\u4e8e\u6307\u5b9a\u4e00\u4e2a\u653e\u7f6e\u5f02\u5e38\u4ee3\u7801\u7684\u5757\u3002\u5728try\u5757\u4e4b\u540e\u5fc5\u987b\u662fcatch\u6216finally\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6211\u4eec\u4e0d\u80fd\u5355\u72ec\u4f7f\u7528try\u5757\u3002<\/td>\n<\/tr>\n |
\ncatch<\/td>\n | \"catch\"\u5757\u7528\u4e8e\u5904\u7406\u5f02\u5e38\u3002\u5b83\u5fc5\u987b\u5728try\u5757\u4e4b\u524d\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u4e0d\u80fd\u5355\u72ec\u4f7f\u7528catch\u5757\u3002\u4e4b\u540e\u53ef\u4ee5\u7a0d\u540e\u518d\u8fdb\u884c\u963b\u6b62\u3002<\/td>\n<\/tr>\n |
\nfinally<\/td>\n | \"finally\"\u5757\u7528\u4e8e\u6267\u884c\u7a0b\u5e8f\u7684\u91cd\u8981\u4ee3\u7801\u3002\u65e0\u8bba\u662f\u5426\u5904\u7406\u5f02\u5e38\u90fd\u5c06\u6267\u884c\u3002<\/td>\n<\/tr>\n |
\nthrow\/td> <\/td>\n | \"throw\"\u5173\u952e\u5b57\u7528\u4e8e\u5f15\u53d1\u5f02\u5e38\u3002<\/td>\n<\/tr>\n |
\nthrows<\/td>\n | \"throws\"\u5173\u952e\u5b57\u7528\u4e8e\u58f0\u660e\u5f02\u5e38\u3002\u5b83\u4e0d\u4f1a\u5f15\u53d1\u5f02\u5e38\u3002\u5b83\u6307\u5b9a\u65b9\u6cd5\u4e2d\u53ef\u80fd\u53d1\u751f\u5f02\u5e38\u3002\u5b83\u603b\u662f\u4e0e\u65b9\u6cd5\u7b7e\u540d\u4e00\u8d77\u4f7f\u7528\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Java\u5f02\u5e38\u5904\u7406\u793a\u4f8b<\/h2>\n\n \u6211\u4eec\u6765\u770b\u4e00\u4e2aJava\u5f02\u5e38\u5904\u7406\u793a\u4f8b\uff0c\u5728\u8be5\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528try-catch\u8bed\u53e5\u6765\u5904\u7406\u5f02\u5e38\u3002\n <\/div>\n \n public <\/span>class <\/span>JavaExceptionExample{ public <\/span>static void <\/span>main(String args[]){ try{ \/\/code that may raise exception int <\/span>data=100\/0; } catch(ArithmeticException e){ System.out.println<\/span>(e); } \/\/rest <\/span>code of the program System.out.println<\/span>(\"rest <\/span>of the code...\"<\/span>); } } <\/span><\/code><\/pre>\n<\/p><\/div>\n\n \u8f93\u51fa:\n <\/div>\n \n Exception in thread main java.lang.ArithmeticException:\/ by zerorest <\/span>of the code... <\/span><\/code><\/pre>\n<\/p><\/div>\n\n \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c100\/0 \u5f15\u53d1ArithmeticException\uff0c\u8be5\u5f02\u5e38\u7531try-catch\u5757\u5904\u7406\u3002\n <\/div>\n
\n Java\u5f02\u5e38\u7684\u5e38\u89c1\u60c5\u51b5<\/h2>\n\n \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u672a\u7ecf\u68c0\u67e5\u7684\u5f02\u5e38\u3002\u5b83\u4eec\u5982\u4e0b:\n <\/div>\n 1)\u53d1\u751fArithmeticException\u7684\u60c5\u51b5<\/h3>\n\n \u5982\u679c\u5c06\u4efb\u4f55\u6570\u5b57\u9664\u4ee5\u96f6\uff0c\u5c31\u4f1a\u53d1\u751fArithmeticException\u3002\n <\/div>\n \n int <\/span>a=50\/0; \/\/ArithmeticException <\/span><\/code><\/pre>\n<\/p><\/div>\n \n 2)\u53d1\u751fNullPointerException\u7684\u60c5\u51b5<\/h3>\n\n \u5982\u679c\u6211\u4eec\u5728\u4efb\u4f55\u53d8\u91cf\u4e2d\u90fd\u6709\u7a7a\u503c\uff0c\u5219\u6267\u884c\u5bf9\u53d8\u91cf\u7684\u4efb\u4f55\u64cd\u4f5c\u90fd\u5c06\u5f15\u53d1NullPointerException\u3002\n <\/div>\n \n String s=null; System.out.println<\/span>(s.length<\/span>()); \/\/NullPointerException <\/span><\/code><\/pre>\n<\/p><\/div>\n \n 3)\u53d1\u751fNumberFormatException\u7684\u60c5\u51b5<\/h3>\n\n \u4efb\u4f55\u503c\u7684\u683c\u5f0f\u9519\u8bef\u90fd\u53ef\u80fd\u53d1\u751fNumberFormatException\u3002\u5047\u8bbe\u6211\u6709\u4e00\u4e2a\u5305\u542b\u5b57\u7b26\u7684string\u53d8\u91cf\uff0c\u5c06\u8be5\u53d8\u91cf\u8f6c\u6362\u4e3a\u6570\u5b57\u5c06\u53d1\u751fNumberFormatException\u3002\n <\/div>\n \n String s=\"abc\"<\/span>; int <\/span>i=Integer.parseInt<\/span>(s); \/\/NumberFormatException <\/span><\/code><\/pre>\n<\/p><\/div>\n \n 4)\u53d1\u751fArrayIndexOutOfBoundsException\u7684\u60c5\u51b5<\/h3>\n\n \u5982\u679c\u5728\u9519\u8bef\u7684\u7d22\u5f15\u4e2d\u63d2\u5165\u4efb\u4f55\u503c\uff0c\u5c06\u5bfc\u81f4ArrayIndexOutOfBoundsException\uff0c\u5982\u4e0b\u6240\u793a:\n <\/div>\n \n int <\/span>a[]=new int[5]; a[10]=50; \/\/ArrayIndexOutOfBoundsException <\/span><\/code><\/pre>\n<\/p><\/div>\n Java\u5f02\u5e38\u7d22\u5f15<\/h2>\n Java try-catch <\/span> \n Java\u591a\u91cd\u6355\u83b7\u5757 <\/span> \n Java try\u5d4c\u5957 <\/span> \n Java finally\u5173\u952e\u5b57 <\/span> \n Java Throw\u5173\u952e\u5b57 <\/span> \n Java\u5f02\u5e38\u4f20\u64ad <\/span> \n Java Throws\u5173\u952e\u5b57 <\/span> \n Java Throw vs Throws <\/span> \n Java Final vs Final vs Finalize <\/span> \n \u5177\u6709\u65b9\u6cd5\u8986\u76d6\u7684Java\u5f02\u5e38\u5904\u7406 <\/span> \n Java\u81ea\u5b9a\u4e49\u5f02\u5e38 <\/span> \n <\/body> \n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Java \u5f02\u5e38\u5904\u7406zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111],"tags":[],"class_list":["post-732","post","type-post","status-publish","format-standard","hentry","category-java-jichu"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/732"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=732"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/732\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
|