{"id":935,"date":"2022-10-15T18:01:02","date_gmt":"2022-10-15T10:01:02","guid":{"rendered":"https:\/\/qaqaq.top\/?p=935"},"modified":"2022-11-27T12:39:52","modified_gmt":"2022-11-27T04:39:52","slug":"%e5%bc%82%e5%b8%b8%e5%a4%84%e7%90%86-%e5%bc%82%e5%b8%b8%e7%9a%84%e5%88%86%e7%b1%bb%e3%80%81%e5%b8%b8%e8%a7%81%e5%bc%82%e5%b8%b8%e7%9a%84%e4%b8%be%e4%be%8b","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=935","title":{"rendered":"\u5f02\u5e38\u5904\u7406-\u5f02\u5e38\u7684\u5206\u7c7b\u3001\u5e38\u89c1\u5f02\u5e38\u7684\u4e3e\u4f8b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P372;\r\n\r\nimport java.io.File;\r\nimport java.io.FileInputStream;\r\nimport java.util.Date;\r\nimport java.util.Scanner;\r\n\r\nimport org.junit.Test;\r\n\r\n\/*\r\n * \u4e00\u3001\u5f02\u5e38\u4f53\u7cfb\u7ed3\u6784\r\n * \r\n * java.lang.Throwable\r\n * \t\t|-----java.lang.Error:\u4e00\u822c\u4e0d\u7f16\u5199\u9488\u5bf9\u6027\u7684\u4ee3\u7801\u8fdb\u884c\u5904\u7406\u3002\r\n * \t\t|-----java.lang.Exception:\u53ef\u4ee5\u8fdb\u884c\u5f02\u5e38\u7684\u5904\u7406\r\n * \t\t\t|------\u7f16\u8bd1\u65f6\u5f02\u5e38(checked)\r\n * \t\t\t\t\t|-----IOException\r\n * \t\t\t\t\t\t|-----FileNotFoundException\r\n * \t\t\t\t\t|-----ClassNotFoundException\r\n * \t\t\t|------\u8fd0\u884c\u65f6\u5f02\u5e38(unchecked,RuntimeException)\r\n * \t\t\t\t\t|-----NullPointerException\r\n * \t\t\t\t\t|-----ArrayIndexOutOfBoundsException\r\n * \t\t\t\t\t|-----ClassCastException\r\n * \t\t\t\t\t|-----NumberFormatException\r\n * \t\t\t\t\t|-----InputMismatchException\r\n * \t\t\t\t\t|-----ArithmeticException\r\n * \r\n * \r\n * \r\n * \u9762\u8bd5\u9898\uff1a\u5e38\u89c1\u7684\u5f02\u5e38\u90fd\u6709\u54ea\u4e9b\uff1f\u4e3e\u4f8b\u8bf4\u660e\r\n * \r\n * \r\n * \r\n * \r\n *\/\r\npublic class ExceptionTest {\r\n\t\r\n\t\/\/****************\u4ee5\u4e0b\u662f\u7f16\u8bd1\u65f6\u5f02\u5e38******************************\r\n\t@Test\r\n\tpublic void test7() {\r\n\/\/\t\tFile file = new File(\"hello.txt\");\r\n\/\/\t\tFileInputStream fis = new FileInputStream(file);\r\n\/\/\t\t\r\n\/\/\t\tint data = fis.read();\r\n\/\/\t\twhile(data != -1) {\r\n\/\/\t\t\tSystem.out.print((char)data);\r\n\/\/\t\t\tdata = fis.read();\r\n\/\/\t\t}\r\n\/\/\t\t\r\n\/\/\t\tfis.close();\r\n\t}\r\n\t\r\n\t\/\/****************\u4ee5\u4e0b\u662f\u8fd0\u884c\u65f6\u5f02\u5e38******************************\r\n\t\r\n\t\/\/ArithmeticException \u7b97\u6570\u5f02\u5e38\r\n\t@Test\r\n\tpublic void test6() {\r\n\t\tint a = 10;\r\n\t\tint b = 0;\r\n\t\tSystem.out.println(a \/ b);\r\n\t}\r\n\t\r\n\t\/\/InputMismatchException \u8f93\u5165\u4e0d\u5339\u914d\u5f02\u5e38\r\n\t@Test\r\n\tpublic void test5() {\r\n\t\tScanner scanner = new Scanner(System.in);\r\n\t\tint score = scanner.nextInt();\r\n\t\tSystem.out.println(score);\r\n\t\t\r\n\t\tscanner.close();\r\n\t}\r\n\t\r\n\t\/\/NumberFormatException \u6570\u503c\u8f6c\u6362\u5f02\u5e38\r\n\t@Test\r\n\tpublic void test4() {\r\n\t\tString str = \"123\";\r\n\t\tstr = \"abc\";\r\n\t\tint num = Integer.parseInt(str);\r\n\t}\r\n\t\r\n\t\/\/ClassCastException \u7c7b\u578b\u8f6c\u6362\u5f02\u5e38\r\n\t@Test\r\n\tpublic void test3() {\r\n\t\tObject obj = new Date();\r\n\t\tString str = (String)obj;\r\n\t}\r\n\t\r\n\t\/\/IndexOutOfBoundsException \u89d2\u6807\u8d8a\u754c\r\n\t@Test\r\n\tpublic void test2() {\r\n\t\t\r\n\t\t\/\/ArrayIndexOutOfBoundsException \u6570\u7ec4\u89d2\u6807\u8d8a\u754c\r\n\/\/\t\tint&#91;] arr = new int&#91;10];\r\n\/\/\t\tSystem.out.println(arr&#91;10]);\r\n\t\t\/\/StringIndexOutOfBoundsException \u5b57\u7b26\u4e32\u89d2\u6807\u8d8a\u754c\r\n\t\tString str = \"abc\";\r\n\t\tSystem.out.println(str.charAt(3));\r\n\t}\r\n\r\n\t\/\/NullPointerException \u7a7a\u6307\u9488\u5f02\u5e38\r\n\t@Test\r\n\tpublic void test1() {\r\n\t\t\r\n\/\/\t\tint&#91;] arr = null;\r\n\/\/\t\tSystem.out.println(arr&#91;3]);\r\n\t\t\r\n\t\tString str = \"abc\";\r\n\t\tstr = null;\r\n\t\tSystem.out.println(str.charAt(0));\r\n\t}\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-935","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/935"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=935"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/935\/revisions"}],"predecessor-version":[{"id":936,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/935\/revisions\/936"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}