Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions