??????Exception??????????????????????????CheckedException????????????????UncheckedException?????????????????CheckException??????????Σ?????????try…catch??????throws????????????????UncheckedException????????????????в?????????????????????????????????????????飬???????????????????????????????????????????????????????????濼????ú?д???????????????????????????????????????????????????????
??????????????????????????????????CheckedException?????????????????????????????????????????????????RuntimeException????
????java??????????????????????????????????????????????????????????java?о????????????????λ???????
????????????
??????????????????????Ц????????????????????????????try????catch???????????????????????????????????????????????????try…catch?????????????????????????????????try…catch????????о?try…catch????????????????
??????????try????????????????????飬catch?鯰????????????д????????????????
public class ExceptionTest {
public static void main(String[] args) {
String file = "D:\exceptionTest.txt";
FileReader reader;
try {
reader = new FileReader(file);
Scanner in = new Scanner(reader);
String string = in.next();
System.out.println(string + "????????????????е???.....");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("?????????в???...");
}
finally{
System.out.println("finally ?????...");
}
}
}
????????η???????????????D?????μ?exceptionText.txt?????????????е???????????????D????и?????????г????????£?
????java.io.FileNotFoundException: D:exceptionTest.txt (?????????????????)
????at java.io.FileInputStream.open(Native Method)
????at java.io.FileInputStream.<init>(FileInputStream.java:106)
????at java.io.FileInputStream.<init>(FileInputStream.java:66)
????at java.io.FileReader.<init>(FileReader.java:41)
????at com.test9.ExceptionTest.main(ExceptionTest.java:19)
?????????????в???...
????finally ?????...
????????????????????????Щ??
????1????????????????????????????У???????????????У?????????????????????????
????2??catch????????????????????
????????????D????????????exceptionTest.txt????????г????????£?
????1111????????????????е???.....
????finally ?????...
????11111???????е??????????????н??????ó?????????????????????????finally????????????С?????finally???????????????
????????????????????3???
????public class ExceptionTest {
????public static void main(String[] args) {
????int[] a = {1??2??3??4};
????System.out.println(a[4]);
????System.out.println("????????????");
????}
????}
???????????н????
????Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
????at com.test9.ExceptionTest.main(ExceptionTest.java:14)
??????λ?????????????????????????????????????????????????????????
????java.io.FileNotFoundException: D:exceptionTest.txt (?????????????????)
????Exception in thread "main" <strong>java.lang.ArrayIndexOutOfBoundsException:</strong> 4
???????????????????????????????????????????????????Exception in thread ”main”???????????????????λ?á??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????Java?????????????????????????????????????????????try…catch??throw??throws??????λ??????????????