First, the abnormal architecture
* java.lang.Throwable
* |-----error: errors, not processed in program
* |-----Exception: Exceptions that require handling of these exceptions when writing a program
* |-----Compile-TIME Exception: An exception that occurs during compilation (an exception occurs when the Javac.exe command is executed)
* |-----Run-TIME Exception: An exception that occurs during run time (an exception occurs when the Java.exe command is executed)
*
* When executing a program, if an exception occurs, then the code after the exception is no longer executed!
ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.util.Date;ImportJava.util.Scanner;Importorg.junit.Test; Public classTestException {//compile-time exceptions@Test Public voidTest6 () {//FileInputStream fis = new FileInputStream (New File ("Hello.txt"));//int b;//While ((b = Fis.read ())! =-1) {//System.out.println ((char) b);// }//fis.close (); } //Common run-time exceptions//4. Null pointer exception: Nullpointerexcetion@Test Public voidTest5 () {//Person p = new Person ();//p = null;//System.out.println (p.tostring ());String str=NewString ("AA"); STR=NULL; System.out.println (Str.length ()); } //3. Type Conversion exception: ClassCastException@Test Public voidtest4 () {Object obj=NewDate (); String Str=(String) obj; //String str1 = (string) new Date (); } //2. Arithmetic exception: ArithmeticException@Test Public voidtest3 () {inti = 10; System.out.println (i/0); } //1. Array subscript out-of-bounds exception: ArrayIndexOutOfBoundsException@Test Public voidtest2 () {int[] i =New int[10]; //System.out.println (i[10]);System.out.println (i[-10]); } @Test Public voidtest1 () {Scanner s=NewScanner (system.in); inti =S.nextint (); System.out.println (i); }}classperson{}
Java Learning--exception exception