No.
Here is the example program modified to include a finally{}
catch{}
for InputMismatchException
has been removed.
Now these exceptions cause a jump out of the try{}
finally{}
import java.util.* ; public class FinallyPractice { public static void main ( String[] a ) { Scanner scan = new Scanner( System.in ); int num=0, div=0 ; try { System.out.print("Enter the numerator: "); num = scan.nextInt(); System.out.print("Enter the divisor : "); div = scan.nextInt(); System.out.println( num + " / " + div + " is " + (num/div) + " rem " + (num%div) ); } catch (ArithmeticException ex ) { System.out.println("You can't divide " + num + " by " + div); } finally { System.out.println("If something went wrong, you entered bad data." ); } } }
If the user enters good data, the finally{}
Enter the numerator: 13 Enter the divisor : 4 13 / 4 is 3 rem 1 If something went wrong, you entered bad data.
If the user enters bad data, the finally{}
Enter the numerator: rats If something went wrong, you entered bad data. Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at FinallyPractice.main(FinallyPractice.java:13)
Where did the last 6 lines of output come from?