Java Exception class and its subclass, javaexception class
If... else... to control exceptions. All exceptions in the Java language can be represented by a class. Different types of exceptions correspond to different subclass exceptions, and each exception corresponds to an object of the exception class.
Java exception handling is managed by five keywords: try, catch, finally, throw, and throws. The basic process is to use try to wrap the statement to be monitored. If an exception occurs in try, the exception will be thrown. catch will capture and handle the thrown exception, finally will definitely complete the unfinished tasks.
Exercise:
Package com. swift; public class Exception1 {public static void main (String args []) {System. out. println ("========= computing start ========"); try {int I = Integer. parseInt (args [0]); int j = Integer. parseInt (args [1]); int temp = I/j; System. out. println ("Calculation Result:" + temp);} catch (ArithmeticException e) {System. out. println ("A mathematical exception occurred" + e);} catch (ArrayIndexOutOfBoundsException e) {System. out. println ("an array exception occurred" + e);} catch (Nu MberFormatException e) {System. out. println ("format Exception" + e);} catch (Exception e) {System. out. println ("Other exceptions" + e);} finally {System. out. println ("whether or not there is an exception, I will execute it. ");} System. out. println (" ========= computing end ======== ");}}