1 /*2 JDK7 A new exception-handling scenario has occurred:3 try{4 5 }catch (Exception name 1 | exception Name 2 | ... Variable) {6 ...7 }8 if the compile-time exception, and do not know the name of the exception, follow-up look at the source, where the face can find9 Note : This method is simple, but not good enough. Ten A: The processing method is consistent. (In actual development, many times may be for the same type of problem, give the same treatment) One B: Multiple exceptions must be a peer relationship. A */ - Public classExceptionDemo3 { - Public Static voidMain (string[] args) { the method (); - } - - Public Static voidmethod () { + intA = 10; - intb = 0; + int[] arr = {1, 2, 3 }; A at //try { - //System.out.println (A/b); - //System.out.println (arr[3]); - //System.out.println ("There's an anomaly here, you don't know who it is, what to do?"); - //} catch (ArithmeticException e) { - //System.out.println ("divisor cannot be 0"); in //} catch (ArrayIndexOutOfBoundsException e) { - //System.out.println ("You visited the index of the wrong Access"); to //} catch (Exception e) { + //System.out.println ("problem"); - // } the * //the treatment scheme of JDK7 $ Try {Panax NotoginsengSystem.out.println (A/b); -System.out.println (arr[3]); the}Catch(ArithmeticException |arrayindexoutofboundsexception e) { +System.out.println ("Something's Wrong"); A } the +System.out.println ("Over"); - } $ $}
Java 19-3 JDK7 handling of multiple exceptions