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