Question: Explain what happens if an exception occurs half-way through executing a block of code that is surrounded by a ' try ' block that is

  1. Explain what happens if an exception occurs half-way through executing a block of code that is surrounded by a 'try' block that is followed by severalcatch() blocks that have their own code blocks
  2. Complete the code for a driver classTwoErrors to demonstrate your explanation in (a).

The main method should :

  • Declare three integers and an integer array with three elements.
  • have atry{ } block which
    1. shows a division of 0, using your integer variables, which will (obviously) throw anArithmeticException
    2. assigns an array element to an integer, which will cause anArrayIndexOutOfBoundsException
  • have the respectivecatch() blocks, as well as acatch()block that handles generic Exceptions.
  • Code simple messages or use theprintStackTrace orgetMessage options in thecatch() blocks.
  • have afinally block that shuts your system down because there is an error.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!