Handling of multiple exceptions
1, when declaring an exception, it is recommended to declare more specific exceptions, so that the treatment can be more targeted
2, the other side of the declaration of a few exceptions, you should have a few catch blocks, do not define redundant catch blocks
If an inheritance relationship occurs in multiple catch blocks, the parent exception catch block is placed at the bottom.
Attention:
/* When you make catch processing, you must define the specific handling in the catch.
Do not simply define a sentence e.printstacktrace (),----because the user cannot read
Also do not simply write an output statement */
There is a problem, in the catch inside the set up, log the problem to the log file for maintenance personnel to view.
--------------------------
Exceptiontest.java
Public classExceptiontest { Public Static voidMain (string[] args) {Divdemo dd=NewDivdemo (); intResultd; Try{Resultd= Dd.div (10, 0); System.out.println ("Resultd ' value is:" +Resultd); } Catch(ArithmeticException e) {e.printstacktrace (); } Catch(arrayindexoutofboundsexception e) {e.printstacktrace (); } Catch(Exception e) {e.printstacktrace (); } System.out.println ("Over!"); }}classdivdemo{ Public intDivintAintbthrowsarithmeticexception,arrayindexoutofboundsexception {int[] arr =New int[5]; System.out.println (Arr[a]); returnA/b; }}
: Console:
Java Basics-Exception--handling of multiple exceptions