public static void main(String args[])
{
   int a, b;
   try
   {
      a = 0;
      b = 42 / a;
      System.out.println("This will not be printed.");
   }  
?
   catch (ArithmeticException e)
   {
      System.out.println("Division by zero.");
   }
   System.out.println("After catch statement.");
}
?
The program above includes a try block and a catch clause that processes the ArithmeticException generated by the division-by-zero error. Explain how the try and catch blocks operate, and what the output will be following program execution.

What will be an ideal response?

The call to the println() statement inside the try block is never executed. Once an exception is thrown, program control transfers out of the try block into the catch block. The catch is not "called," so execution never "returns" to the try block from a catch. Thus, the line "This will not be printed." is not displayed. Once the catch statement has executed, program control continues with the next line in the program following the entire try/catch pair.

Computer Science & Information Technology

You might also like to view...

The ________ view in PowerPoint replaces the thumbnails on the left of the presentation with an outline format

Fill in the blank(s) with correct word

Computer Science & Information Technology

A closed operating system allows

A) Modifications by anyone who finds it on his/her PC B) Modifications by anyone who distributes it C) Modifications only by those designated by the developer D) Modifications to the open source of the designer

Computer Science & Information Technology