???java?????throw??throws
???????????? ???????[ 2016/6/3 10:39:38 ] ??????????????????? Java
??????????????Щ??????????ù??Щ???????throw??throws???????в????????????????????
?????????????
?????????????????????????д???????????????????????????????????????????????
????????????????????????????????????????
?????????
???????????????????????throw?????throws?????????????????????????????????????
?????????????
?????????????????Щ????????????????????????????????????????????磺
????public static void main(String[] args) {
????int a = 5?? b =0;
????System.out.println(5/b);
????//function();
????}
??????????????ArithmeticException????
????Exception in thread "main" java.lang.ArithmeticException: / by zero
????at test.ExceptionTest.main(ExceptionTest.java:62)
????????
????public static void main(String[] args) {
????String s = "abc";
????System.out.println(Double.parseDouble(s));
????//function();
????}
??????????????NumberFormatException????
????Exception in thread "main" java.lang.NumberFormatException: For input string: "abc"
????at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
????at java.lang.Double.parseDouble(Double.java:510)
????at test.ExceptionTest.main(ExceptionTest.java:62)
????throw
????throw???????????????
????????throw (??????);
?????磺 throw e;
?????????????????????????????????????????????????????磺
public static void main(String[] args) {
String s = "abc";
if(s.equals("abc")) {
throw new NumberFormatException();
} else {
System.out.println(s);
}
//function();
}
?????????????
????Exception in thread "main" java.lang.NumberFormatException
????at test.ExceptionTest.main(ExceptionTest.java:67)
????throws
????throws??????????????????????(???????????????????÷?????????????)
????????[(???η?)](?????????)(??????)([?????б?])[throws(????)]{......}
?????磺 public void function() throws Exception{......}
???????????????????????????????throws ???????????????????????????????????????????磺
public static void function() throws NumberFormatException{
String s = "abc";
System.out.println(Double.parseDouble(s));
}
public static void main(String[] args) {
try {
function();
} catch (NumberFormatException e) {
System.err.println("??????????????????");
//e.printStackTrace();
}
}
?????????????£?
??????????????????????
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11