Java Section 45th Java exception Quick Start

Source: Internet
Author: User

2016-06-30

1 What is an exception
Exception is the abnormal phenomenon that occurs during the process of running the program.
Try: Packages the code that may have an exception, throws an exception when an exception occurs
Catch: Catching exceptions and handling
Finally: executes regardless of whether an exception occurs
Throw: Throw an exception manually
Throws: Defines the exception of any called method
2 Causes of abnormal occurrences
User input Error
Code Error
Environmental factors
Abnormal mechanism ensures the robustness of the program

 Packagecom.java1995; Public classTest { Public Static voidMain (string[] args) {Try{System.out.println (1/0); System.out.println ("AAA"); //Open File//Read File Error//Close File}Catch(ArithmeticException e) {System.out.println ("Arithmetic Error");        E.printstacktrace (); }finally{System.out.println ("Always executes."); //close the file, first detect whether the file is closed, or close the file if it is not closed//if it is already closed, it is not processed        }    }}

Resources

[1] Java Easy Start Classic tutorial "full version"

Java Section 45th Java exception Quick Start

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.