???????????
????1. checked??
?????????????InvalidUrlException
public class InvalidUrlException extends Exception {
public InvalidUrlException(String s){
super(s);
}
}
public class Main {
public static void getRemoteData(String url) throws InvalidUrlException{
if(isValidUrl(url)){
//??????????
}
else
throw new InvalidUrlException("Invalid URL: " + url);
}
public static boolean isValidUrl(String url){
.... //???URL?????Ч
}
public static void main(String[] args) {
getRemoteData(args[0]);
}
}
?????????main?????????getRemoteData???????????????????try-catch???????????????main????throws InvalidUrlException??
????2. unchecked??
?????????InvalidUrlException???extends RuntimeException??
????public class InvalidUrlException extends Exception {
????public InvalidUrlException(String s){
????super(s);
????}
????}
???????main????????throws????try-catch??
???????checked????unchecked????
?????ЩJava?鼮???????checked??????????????п?????????????unchecked???????????????????????????Щ?????RuntimeException??Java????????????????л?????????NullPointerException??IllegalArgumentExceptions????0??????????????????????????????С?????Щ???????????????????У????????????????????????????????????????????????????????????????
???????????????????checked?????Щ???
??????????????????????unchecked?????????????????????????
???????checked???????????????throws??throws????????????????????????????汾?????????????????????????
????unchecked????????????????????????????????
????????checked?????????????????????????????????????????????????
???????checked????unchecked?????????????????????????????????????????????????????е??????У?Java????????checked?????????????????????unchecked????