Java 19-3 JDK7 handling of multiple exceptions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.