<<< InputMismatchException class | Index | The catch Blocks >>> |
A try statement that catches an InputMismatchException
double subtotal = 0.0; try { System.out.print("Enter subtotal: "); subtotal = sc.nextDouble(); } catch (InputMismatchException e) { sc.next(); // discard the incorrectly entered double System.out.println( "Error! Invalid number. Try again.\n"); continue; // jump to the top of the loop }
<<< InputMismatchException class | Index | The catch Blocks >>> |