Some problems to be aware of when multiple anomalies are observed

Source: Internet
Author: User

  

1  Packageexception;2 3 Importjava.util.InputMismatchException;4 ImportJava.util.Scanner;5 6  Public classMorecatch {7     /*Multiple Catch blocks8 a piece of code can throw more than one type of exception. At this point, we can immediately follow a block of a try statement with multiple catch statements, handling different exceptions separately. 9 here, it is important to note that the exception types handled in multiple catch blocks must be from special to general, and the last is generally the exception class*/Ten      Public Static voidMain (String args []) One     {    AScanner input =NewScanner (system.in);  -                      while(true) -                     { the                         Try   -                         {    -System.out.println ("Please enter total hours of S1:");  -                                  intTotalTime =Input.nextint ();  +System.out.println ("Please enter the total account:");  -                                  intTotalcourse =Input.nextint ();  +System.out.println ("Average class hours are:" + totaltime/totalcourse);  A                         }    at                          Catch(Inputmismatchexception ex) -                         {    - Ex.printstacktrace ();  -                         }    -                         Catch(ArithmeticException ex) -                        {    in Ex.printstacktrace ();  -                        }    to                     } +                      -     }    the     /*a piece of code can throw more than one type of exception. At this point, we can immediately follow a block of a try statement with multiple catch statements, handling different exceptions separately.  * here, it is important to note that the exception types handled in multiple catch blocks must be from special to general, and the last is generally the exception class*/ $     Panax Notoginseng     /*at run time, the system detects the exception type handled by each CATCH statement block from top to bottom, and executes the first catch statement that matches the exception type. Performed a - after a catch statement, subsequent catch statements are ignored. A match is a catch that handles an exception type that exactly matches the generated exception type or its superclass.  the If the program produces an exception type that does not match the exception that is handled by the catch, then the exception is caught and processed by the JVM, with no exception handling being + the same. */ A  the}

Some problems to be aware of when multiple anomalies are observed

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.