C language with If...else ... To control exceptions,all exceptions in the Java language can be represented by a class, and 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 5 keyword try, catch, finally, throw, throws. The basic process is to use a try to wrap the statement to be monitored, if an exception occurs within a try, the exception is thrown, the catch catches the thrown exception and is processed, and finally will certainly complete the unfinished matter.
Practice:
PackageCom.swift; Public classexception1{ Public Static voidMain (String args[]) {System.out.println ("========= Calculation begins ========="); Try{ intI=integer.parseint (args[0]); intJ=integer.parseint (args[1]); inttemp=i/J; System.out.println ("Calculation Result:" +temp); }Catch(ArithmeticException e) {System.out.println ("There was a mathematical anomaly" +e); }Catch(arrayindexoutofboundsexception e) {System.out.println ("An array exception has occurred" +e); }Catch(NumberFormatException e) {System.out.println ("Format exception has occurred" +e); }Catch(Exception e) {System.out.println ("Other exceptions" +e); }finally{System.out.println ("Regardless of whether there is an exception, I do." "); } System.out.println ("========= Compute End ========="); }}
Java exception Exception class and its subclasses