• Home
  • Textbooks
  • Introduction to Programming with Java: A Problem Solving Approach
  • Exception Handling

Introduction to Programming with Java: A Problem Solving Approach

John S. Dean, Raymond H. Dean

Chapter 14

Exception Handling - all with Video Answers

Educators


Chapter Questions

00:45

Problem 1

If your program contains an API method call, you should put it inside a try block. To be fully compliant with proper coding practice, you should apply this rule for all your API method calls. $(\mathrm{T} / \mathrm{F})$.

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
00:45

Problem 2

A try block and its associated catch block(s) must be contiguous. (T / F).

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
00:21

Problem 3

Usually, you should try to aggregate related dangerous statements in the same try block to minimize clutter. $(\mathrm{T} / \mathrm{F})$

Amy Jiang
Amy Jiang
Numerade Educator
02:09

Problem 4

Where should you put safe statements that use the results of dangerous operations?

Keenan Mintz
Keenan Mintz
University of Miami
01:01

Problem 5

If an exception is thrown, the JVM jumps to a matching catch block, and after executing the catch block, it returns to the try block at the point where the exception was thrown. (T / $\mathrm{F}$ )

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
06:11

Problem 6

In checking for compile-time errors, the compiler takes into account that all statements inside a try block might get skipped. (T / F)

Anas Venkitta
Anas Venkitta
Numerade Educator
01:01

Problem 7

If an exception is derived from the RuntimeException class it is a(n) ___________ exception.

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
02:02

Problem 8

Checked exceptions are exceptions that are in or derived from the __________ class, but not in or
derived from the___________ class.

Foster Wisusik
Foster Wisusik
Numerade Educator
01:01

Problem 9

In the following list, indicate whether each option is a viable option for an unchecked exception that you know your program might throw:
a) Ignore it.
b) Rewrite the code so that the exception never occurs.
c) Put it in a try block, and catch it in a following catch block.

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:21

Problem 10

When a statement might throw a checked exception, you can keep the compiler from complaining if you put that statement in a try block and follow the try block with a catch block whose parameter type is the same as the exception type. (T / F).

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:21

Problem 11

You can determine whether a particular statement contains a checked exception and the type of that exception by attempting to compile with no try-catch mechanism. (T / $\mathrm{F}$ )

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:21

Problem 12

Is it OK to include code that can throw both unchecked and checked exceptions in the same try block?

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:41

Problem 13

What type of exception matches all checked exceptions and all unchecked exceptions except those derived from the Error class?

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
02:37

Problem 14

What does the getMessage method return?

Ameer Said
Ameer Said
Numerade Educator
01:21

Problem 15

For each distinct type of exception that might be thrown, there must be a separate catch block. (T / F)

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
02:54

Problem 16

The compiler automatically checks for out-of-order catch blocks. (T / $\mathrm{F}$ )

SS
Sarvesh Somasundaram
Numerade Educator
02:55

Problem 17

What are the two types of information displayed by the JVM when it encounters a runtime error that terminates execution?

SS
Sarvesh Somasundaram
Numerade Educator
00:45

Problem 18

Suppose you want to postpone catching of a NumberFormatException. What should you append to the heading of a method to alert the compiler and a potential user that something in the method might throw that type of exception?

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator
01:01

Problem 19

Given a non-void method that contains no try and catch blocks. If the method throws an exception, we know that the JVM transfers the thrown exception back to the calling method. But does the JVM return a value (with a return statement) to the calling module?

Benjamin Schreyer
Benjamin Schreyer
Numerade Educator