Answered step by step
Verified Expert Solution
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
- 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
- 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
- shows a division of 0, using your integer variables, which will (obviously) throw anArithmeticException
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started