On exceptions in Java

Source: Internet
Author: User

The difference between runtimeexception and checked exception:

1. There are two types of errors: Throwable two species of Errow and Exception

Exception errors caused by the encoding:

e.g:

int b=0;
int a=5/b;
System.out.println (a);

2.try Catch Finally catch exception

Put code that might appear to be abnormal, put it in a try

catch (Exception e) {}

Finally is the final meaning, whatever it is, it will be executed.

e.g:

public static void Main (string[] args) {//when input is incorrect

do{
Scanner input=new Scanner (system.in);
System.out.println ("Please enter a number:");
try{
int A=input.nextint ();
SYSTEM.OUT.PRINTLN ("You have entered the correct" +a);
Break
}catch (Exception e) {//error type when run
SYSTEM.OUT.PRINTLN ("Input error, please re-enter");


}
finally {
System.out.println ("1");

}
}while (TRUE);

}

3.throw and Thows differences

Throw throws the object throw A; Exception a=new Exception)

throws throws a declaration e.g throws Exception


4. Check for exceptions, when used, require a try catch exception

5. Exception rewriting

Overrides throw exceptions that are smaller than the parent class or are the same as the default and parent classes

Still follow exception handling when the main method is executed

The above are all small knowledge, * * *

On exceptions in Java

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.