Java Learning--exception exception

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.