text: (window.webpackJsonp=window.webpackJsonp||[]).push([[22],{121:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return b})),n.d(t,"metadata",(function(){return r})),n.d(t,"rightToc",(function(){return o})),n.d(t,"default",(function(){return u}));var i=n(2),a=n(6),l=(n(0),n(162)),c=n(173),b={id:"exception",title:"\u5f02\u5e38\u673a\u5236",author:"Vero",hide_title:!0},r={id:"notes/java/oop/core/exception",title:"\u5f02\u5e38\u673a\u5236",description:"\u5f02\u5e38\u673a\u5236\uff08\u91cd\u70b9\uff09",source:"@site/docs/notes/java/oop/core/exception.mdx",permalink:"/notes/java/oop/core/exception",sidebar:"notes",previous:{title:"\u96c6\u5408\u7c7b\u5e93\uff08\u4e8c\uff09",permalink:"/notes/java/oop/core/collection-2"},next:{title:"File\u7c7b",permalink:"/notes/java/oop/core/file"}},o=[{value:"\u5f02\u5e38\u673a\u5236\uff08\u91cd\u70b9\uff09",id:"\u5f02\u5e38\u673a\u5236\uff08\u91cd\u70b9\uff09",children:[{value:"\u57fa\u672c\u6982\u5ff5",id:"\u57fa\u672c\u6982\u5ff5",children:[]},{value:"\u5f02\u5e38\u7684\u5206\u7c7b",id:"\u5f02\u5e38\u7684\u5206\u7c7b",children:[]},{value:"\u5f02\u5e38\u7684\u907f\u514d",id:"\u5f02\u5e38\u7684\u907f\u514d",children:[]},{value:"\u5f02\u5e38\u7684\u6355\u83b7",id:"\u5f02\u5e38\u7684\u6355\u83b7",children:[]},{value:"\u5f02\u5e38\u7684\u629b\u51fa",id:"\u5f02\u5e38\u7684\u629b\u51fa",children:[]},{value:"\u81ea\u5b9a\u4e49\u5f02\u5e38",id:"\u81ea\u5b9a\u4e49\u5f02\u5e38",children:[]}]}],p={rightToc:o};function u(e){var t=e.components,n=Object(a.a)(e,["components"]);return Object(l.b)("wrapper",Object(i.a)({},p,n,{components:t,mdxType:"MDXLayout"}),Object(l.b)("h2",{id:"\u5f02\u5e38\u673a\u5236\uff08\u91cd\u70b9\uff09"},"\u5f02\u5e38\u673a\u5236\uff08\u91cd\u70b9\uff09"),Object(l.b)("h3",{id:"\u57fa\u672c\u6982\u5ff5"},"\u57fa\u672c\u6982\u5ff5"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u5728java\u8bed\u8a00\u4e2d\u6307\u7a0b\u5e8f\u8fd0\u884c\u65f6\u53d1\u751f\u7684\u5f02\u5e38\u60c5\u51b5"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"java.lang.Throwable"),"\u7c7b\u662fjava\u8bed\u8a00\u4e2d\u9519\u8bef",Object(l.b)("inlineCode",{parentName:"li"},"Error"),"\u548c\u5f02\u5e38",Object(l.b)("inlineCode",{parentName:"li"},"Exception"),"\u7684\u8d85\u7c7b"),Object(l.b)("li",{parentName:"ul"},"\u5176\u4e2d",Object(l.b)("inlineCode",{parentName:"li"},"Error"),"\u7c7b\u4e3b\u8981\u7528\u4e8eJVM\u65e0\u6cd5\u89e3\u51b3\u7684\u4e25\u91cd\u9519\u8bef"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"Exception"),"\u7c7b\u4e3b\u8981\u63cf\u8ff0\u56e0\u7f16\u7a0b\u9519\u8bef\u6216\u5076\u7136\u7684\u5916\u5728\u56e0\u7d20\u5bfc\u81f4\u7684\u8f7b\u5fae\u9519\u8bef")),Object(l.b)("h3",{id:"\u5f02\u5e38\u7684\u5206\u7c7b"},"\u5f02\u5e38\u7684\u5206\u7c7b"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"java.lang.Exception"),"\u7c7b\u662f\u6240\u6709\u5f02\u5e38\u7684\u8d85\u7c7b",Object(l.b)("ul",{parentName:"li"},Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"RuntimeException"),"\u8fd0\u884c\u65f6\u5f02\u5e38\uff0c\u4e5f\u53eb\u975e\u68c0\u6d4b\u6027\u5f02\u5e38"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"IOException"),"\u548c\u5176\u5b83\u5f02\u5e38\uff0c\u4e5f\u53eb\u68c0\u6d4b\u6027\u5f02\u5e38\uff08\u7f16\u8bd1\u9636\u6bb5\u80fd\u88ab\u7f16\u8bd1\u5668\u68c0\u6d4b\u5230\u7684\u5f02\u5e38\uff09"))),Object(l.b)("li",{parentName:"ul"},"\u5176\u4e2d",Object(l.b)("inlineCode",{parentName:"li"},"RuntimeException"),"\u7c7b\u7684\u4e3b\u8981\u5b50\u7c7b\u4e3a\uff1a",Object(l.b)("ul",{parentName:"li"},Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"ArithmeticException")," \u7b97\u672f\u5f02\u5e38"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"ArrayIndexOutOfBoundsException")," \u6570\u7ec4\u4e0b\u6807\u8d8a\u754c\u5f02\u5e38"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"NullPointerException")," \u7a7a\u6307\u9488\u5f02\u5e38"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"ClassCastException")," \u7c7b\u578b\u8f6c\u6362\u5f02\u5e38"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"NumberFormatException")," \u6570\u5b57\u683c\u5f0f\u5f02\u5e38")))),Object(l.b)(c.a,{chart:"\n    graph LR\n      Throwable([Throwable\u7c7b]) --\x3e Error([Error\u7c7b])\n      Throwable([Throwable\u7c7b]) --\x3e Exception([Exception\u7c7b])\n      Exception --\x3e runtime([RuntimeException\u5f02\u5e38])\n      runtime --\x3e arithmetic([ArithmeticException\u5f02\u5e38])\n      runtime --\x3e array([ArrayIndexOutOfBoundsException])\n      runtime --\x3e null([NullPointerException])\n      runtime --\x3e classCast([ClassCastException])\n      runtime --\x3e number([NumberFormatException])\n      Exception --\x3e io([IOException\u5f02\u5e38])\n",mdxType:"Mermaid"}),Object(l.b)("h3",{id:"\u5f02\u5e38\u7684\u907f\u514d"},"\u5f02\u5e38\u7684\u907f\u514d"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u5f00\u53d1\u4e2d\u5c3d\u91cf\u4f7f\u7528if\u6761\u4ef6\u5224\u65ad\u6765\u907f\u514d\u5f02\u5e38\u7684\u53d1\u751f"),Object(l.b)("li",{parentName:"ul"},"\u4f46\u8fc7\u591a\u7684if\u6761\u4ef6\u5224\u65ad\u4f1a\u5bfc\u81f4\u4ee3\u7801\u81c3\u80bf\uff0c\u53ef\u8bfb\u6027\u5dee")),Object(l.b)("h3",{id:"\u5f02\u5e38\u7684\u6355\u83b7"},"\u5f02\u5e38\u7684\u6355\u83b7"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u8bed\u6cd5\u683c\u5f0f")),Object(l.b)("pre",null,Object(l.b)("code",Object(i.a)({parentName:"pre"},{className:"language-java"}),"  try {\n    ...\n  } catch (\u5f02\u5e38\u7c7b\u578b1 e1) {\n    ...\n  } catch (\u5f02\u5e38\u7c7b\u578b2 e2) {\n    ...\n  }\n  ...\n  finally {\n    ...\n  }\n")),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u6ce8\u610f\u4e8b\u9879",Object(l.b)("ul",{parentName:"li"},Object(l.b)("li",{parentName:"ul"},"\u5f53\u9700\u8981\u7f16\u5199\u591a\u4e2a",Object(l.b)("inlineCode",{parentName:"li"},"catch"),"\u65f6\uff0c\u5c0f\u7c7b\u578b\u5e94\u5728\u5927\u7c7b\u578b\u4e4b\u524d"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"catch(Exception e) {}"),"\u61d2\u4eba\u5199\u6cd5"),Object(l.b)("li",{parentName:"ul"},Object(l.b)("inlineCode",{parentName:"li"},"finally"),"\u901a\u5e38\u7528\u4e8e\u8fdb\u884c\u5584\u540e\u5904\u7406")))),Object(l.b)("h3",{id:"\u5f02\u5e38\u7684\u629b\u51fa"},"\u5f02\u5e38\u7684\u629b\u51fa"),Object(l.b)("h4",{id:"\u57fa\u672c\u6982\u5ff5-1"},"\u57fa\u672c\u6982\u5ff5"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u5728\u67d0\u4e9b\u7279\u6b8a\u60c5\u51b5\u4e0b\u4e0d\u80fd\u5904\u7406\u6216\u8005\u4e0d\u4fbf\u4e8e\u5904\u7406\u65f6\uff0c\u5c31\u53ef\u4ee5\u5c06\u8be5\u5f02\u5e38\u8f6c\u79fb\u7ed9\u8c03\u7528\u8005\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53eb\u505a\u5f02\u5e38\u7684\u629b\u51fa\u3002\n\u5f53\u65b9\u6cd5\u6267\u884c\u65f6\u51fa\u73b0\u5f02\u5e38\uff0c\u5219\u5e95\u5c42\u751f\u6210\u4e00\u4e2a\u5f02\u5e38\u7c7b\u5bf9\u8c61\u629b\u51fa\uff0c\u6b64\u65f6\u5f02\u5e38\u4ee3\u7801\u540e\u7eed\u7684\u4ee3\u7801\u4e0d\u518d\u6267\u884c")),Object(l.b)("h4",{id:"\u8bed\u6cd5\u683c\u5f0f"},"\u8bed\u6cd5\u683c\u5f0f"),Object(l.b)("pre",null,Object(l.b)("code",Object(i.a)({parentName:"pre"},{className:"language-java"}),"  public void show() throws IOException {\n    ...\n  }\n")),Object(l.b)("h4",{id:"\u65b9\u6cd5\u91cd\u5199\u539f\u5219"},"\u65b9\u6cd5\u91cd\u5199\u539f\u5219"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u65b9\u6cd5\u540d\u3001\u53c2\u6570\u5217\u8868\u3001\u8fd4\u56de\u503c\u7c7b\u578b\u76f8\u540c\uff0c\u4ecejdk1.5\u5f00\u59cb\u652f\u6301\u8fd4\u56de\u5b50\u7c7b\u7c7b\u578b"),Object(l.b)("li",{parentName:"ul"},"\u8981\u6c42\u65b9\u6cd5\u7684\u8bbf\u95ee\u6743\u9650\u4e0d\u80fd\u53d8\u5c0f\uff0c\u53ef\u4ee5\u76f8\u540c\u6216\u53d8\u5927"),Object(l.b)("li",{parentName:"ul"},"\u8981\u6c42\u65b9\u6cd5\u4e0d\u80fd\u629b\u51fa\u66f4\u5927\u7684\u5f02\u5e38")),Object(l.b)("h4",{id:"\u6ce8\u610f"},"\u6ce8\u610f"),Object(l.b)("p",null,"\u5b50\u7c7b\u91cd\u5199\u7684\u65b9\u6cd5\u4e0d\u80fd\u629b\u51fa\u66f4\u5927\u7684\u5f02\u5e38\uff0c\u4e0d\u80fd\u629b\u51fa\u5e73\u7ea7\u4e0d\u4e00\u6837\u7684\u5f02\u5e38\uff0c\u4f46\u53ef\u4ee5\u629b\u51fa\u4e00\u6837\u7684\u5f02\u5e38\u3001\u66f4\u5c0f\u7684\u5f02\u5e38\u53ca\u4e0d\u629b\u51fa\u5f02\u5e38"),Object(l.b)("h4",{id:"\u7ecf\u9a8c\u5206\u4eab"},"\u7ecf\u9a8c\u5206\u4eab"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u82e5\u7236\u7c7b\u4e2d\u88ab\u91cd\u5199\u7684\u65b9\u6cd5\u6ca1\u6709\u629b\u51fa\u5f02\u5e38\u65f6\uff0c\u5219\u5b50\u7c7b\u4e2d\u91cd\u5199\u7684\u65b9\u6cd5\u53ea\u80fd\u8fdb\u884c\u5f02\u5e38\u7684\u6355\u83b7\u5904\u7406"),Object(l.b)("li",{parentName:"ul"},"\u82e5\u4e00\u4e2a\u65b9\u6cd5\u5185\u90e8\u53c8\u4ee5\u9012\u8fdb\u7684\u65b9\u5f0f\u5206\u522b\u8c03\u7528\u4e86\u597d\u51e0\u4e2a\u5176\u5b83\u65b9\u6cd5\uff0c\u5219\u5efa\u8bae\u8fd9\u4e9b\u65b9\u6cd5\u5185\u53ef\u4ee5\u4f7f\u7528\u629b\u51fa\u7684\u65b9\u6cd5\u5904\u7406\u5230\u6700\u540e\u4e00\u5c42\u8fdb\u884c\u6355\u83b7\u65b9\u5f0f\u5904\u7406")),Object(l.b)("h3",{id:"\u81ea\u5b9a\u4e49\u5f02\u5e38"},"\u81ea\u5b9a\u4e49\u5f02\u5e38"),Object(l.b)("h4",{id:"\u57fa\u672c\u6982\u5ff5-2"},"\u57fa\u672c\u6982\u5ff5"),Object(l.b)("p",null,"\u9488\u5bf9\u67d0\u4e9b\u7279\u5b9a\u573a\u666f\u7684\u5f02\u5e38\uff0c\u9700\u8981\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38\u52a0\u4ee5\u63cf\u8ff0"),Object(l.b)("h4",{id:"\u5b9e\u73b0\u6d41\u7a0b"},"\u5b9e\u73b0\u6d41\u7a0b"),Object(l.b)("ul",null,Object(l.b)("li",{parentName:"ul"},"\u81ea\u5b9a\u4e49",Object(l.b)("inlineCode",{parentName:"li"},"xxxException"),"\u5f02\u5e38\u7c7b\u7ee7\u627f",Object(l.b)("inlineCode",{parentName:"li"},"Exception"),"\u7c7b\u6216\u5176\u5b50\u7c7b")),Object(l.b)("h4",{id:"\u5f02\u5e38\u7684\u4ea7\u751f"},"\u5f02\u5e38\u7684\u4ea7\u751f"),Object(l.b)("pre",null,Object(l.b)("code",Object(i.a)({parentName:"pre"},{className:"language-java"}),"  throw new \u5f02\u5e38\u7c7b\u578b(\u5b9e\u53c2)\n")),Object(l.b)("h4",{id:""}))}u.isMDXComponent=!0},173:function(e,t,n){"use strict";n(187);var i=n(0),a=n.n(i),l=n(188),c=n.n(l);c.a.initialize({startOnLoad:!0});t.a=function(e){var t=e.chart,n=e.style,l=void 0===n?{}:n;return Object(i.useEffect)((function(){c.a.contentLoaded()}),[]),a.a.createElement("div",{className:"mermaid",style:Object.assign({},l)},t)}},197:function(e,t,n){var i={"./locale":172,"./locale.js":172};function a(e){var t=l(e);return n(t)}function l(e){if(!n.o(i,e)){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}return i[e]}a.keys=function(){return Object.keys(i)},a.resolve=l,e.exports=a,a.id=197}}]);