Java try Catch Exception Handling Learning

Source: Internet
Author: User

Exception handling (also known as error handling) features

Used to handle anomalies in software or information systems (i.e., certain special conditions that go beyond the normal execution of a program).

Try....catch .... Just a common method of exception handling

try{

Actions that could cause an exception

}catch{

Defining Exception handlers

}

Give me a chestnut.

1  Public classABC {2     3      Public Static  voidMain (String arg[]) {4         intD;5         intA;6          Try{7D=0; 8A=1;9a=a/D; The denominator is 0 and the code must have an exceptionTenSYSTEM.OUT.PRINTLN ("Output Try statement"); One}Catch(Exception e) { ASYSTEM.OUT.PRINTLN ("Output Catch statement"); -          } -System.out.println ("Over"); the     } -      -}

Execute code Result:

Output Catch statement
Over

It executes the contents of the Catch statement

Change the above d=0 to d=1

1  Public classabc{2     3      Public Static  voidMain (String arg[]) {4         intD;5         intA;6          Try{7d=2;8A=1;9a=a/D;TenSYSTEM.OUT.PRINTLN ("Output Try statement"); One}Catch(Exception e) { ASYSTEM.OUT.PRINTLN ("Output Catch statement"); -          } -System.out.println ("Over"); the     } -      -}

Execute code Result:

Output Try Statement
Over

It executes the contents of the Try Statement

Java try Catch Exception Handling Learning

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.