{"id":947,"date":"2022-10-15T18:04:05","date_gmt":"2022-10-15T10:04:05","guid":{"rendered":"https:\/\/qaqaq.top\/?p=947"},"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%a6%82%e4%bd%95%e8%87%aa%e5%ae%9a%e4%b9%89%e5%bc%82%e5%b8%b8","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=947","title":{"rendered":"\u5f02\u5e38\u5904\u7406-\u5982\u4f55\u81ea\u5b9a\u4e49\u5f02\u5e38"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P382;\r\n\/*\r\n * \u5982\u4f55\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b\uff1f\r\n * 1. \u7ee7\u627f\u4e8e\u73b0\u6709\u7684\u5f02\u5e38\u7ed3\u6784\uff1aRuntimeException\u3001Exception\r\n * 2. \u63d0\u4f9b\u5168\u5c40\u5e38\u91cf\uff1aserialVersionUID\r\n * 3. \u63d0\u4f9b\u91cd\u8f7d\u7684\u6784\u9020\u5668\r\n * \r\n *\/\r\npublic class MyException extends Exception {\r\n\t\r\n\tstatic final long serialVersionUID = -7034897132712766939L;\r\n\t\r\n\tpublic MyException() {\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic MyException(String msg) {\r\n\t\tsuper(msg);\r\n\t}\r\n\t\r\n\t\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P382;\r\n\r\npublic class StudentTest {\r\n\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\t\ttry {\r\n\t\t\tStudent s = new Student();\r\n\t\t\ts.regist(-1001);\r\n\t\t\tSystem.out.println(s);\r\n\t\t} catch (Exception e) {\r\n\/\/\t\t\te.printStackTrace();\r\n\t\t\tSystem.out.println(e.getMessage());\r\n\t\t}\r\n\t}\r\n}\r\n\r\nclass Student{\r\n\t\r\n\tprivate int id;\r\n\t\r\n\tpublic void regist(int id) throws Exception{\r\n\t\t\r\n\t\tif(id > 0) {\r\n\t\t\tthis.id = id;\r\n\t\t}else {\r\n\/\/\t\t\tSystem.out.println(\"\u60a8\u8f93\u5165\u7684\u6570\u636e\u975e\u6cd5\uff01\");\r\n\t\t\t\/\/\u624b\u52a8\u629b\u51fa\u5f02\u5e38\u5bf9\u8c61\r\n\/\/\t\t\tthrow new RuntimeException(\"\u60a8\u8f93\u5165\u7684\u6570\u636e\u975e\u6cd5\uff01\");\r\n\t\t\tthrow new MyException(\"\u4e0d\u80fd\u8f93\u5165\u8d1f\u6570\");\r\n\t\t\t\/\/\u9519\u8bef\u7684\r\n\/\/\t\t\tthrow new String(\"\u4e0d\u80fd\u8f93\u5165\u8d1f\u6570\");\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String toString() {\r\n\t\treturn \"Student &#91;id=\" + id + \"]\";\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-947","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\/947"}],"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=947"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/947\/revisions"}],"predecessor-version":[{"id":948,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/947\/revisions\/948"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}