Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

intro to java ( exceptions chapter) What output is produced by the following code? int waitTime = 46; try { System.out.println(Try blockentered.); if (waitTime> 30)

intro to java ( exceptions chapter)

What output is produced by the following code?

int waitTime = 46;
try
{
System.out.println("Try blockentered.");
if (waitTime> 30)
throw newException("Time Limit Exceeded.");
System.out.println("Leaving tryblock.");
}
catch(Exception e)
{
System.out.println("Exception: " +e.getMessage());
}
System.out.println("After catch block");

2. What output would the code in the previous questionproduce if we changed 46 in the first statement to 12?

3. What is an exception? Is it an identifier? A variable? Amethod? An object? A class? Something else?

4. Is the following statement legal?

Exception myException = new Exception("HiMom!");

5. In the example code in lesson, howwould the program’s behavior change if you were to replace

if (milkCount < 1)
throw new Exception("Exception: Nomilk!");

with the following?

if (milkCount < 1)
{ Exception e = newException("Exception: No milk!");

throw e;
}

6. What happens when a throw statement is executed?

7. In the code given in Question 1, identify the tryblock.

8. In the code given in Question 1, identify the catchblock.

9. In the code given in Question 1, identify thecatch-block parameter.

10. Would the code given in Question 1 perform anydifferently if the catch block were changed to thefollowing?

catch(Exception messenger)
{
System.out.println("Exception: "+
messenger.getMessage());
}

11. Write a statement that will throw an exception of typeException if the value of the String variable named status is"bad". The string recovered by getMessage should be "Exceptionthrown: Bad Status." You need not write the try block and catchblock.

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Programming questions

Question

Write a paragraph describing tenancy by the entireties.

Answered: 1 week ago