??????Exception??????????????????????????CheckedException????????????????UncheckedException?????????????????CheckException??????????危?????????try…catch??????throws????????????????UncheckedException????????????????胁?????????????????????????????????????????椋�???????????????????????????????????????????????????????????婵�????煤?写???????????????????????????????????????????????????????
??????????????????????????????????CheckedException?????????????????????????????????????????????????RuntimeException????
????java??????????????????????????????????????????????????????????java?芯????????????????位???????
????????????
??????????????????????笑????????????????????????????try????catch???????????????????????????????????????????????????try…catch?????????????????????????????????try…catch????????芯?try…catch????????????????
??????????try????????????????????椋琧atch?榀�????????????写????????????????
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??????位??????????????