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