??????????????Щ??????????ù??Щ???????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();
}
}
?????????????£?
??????????????????????