Exam 9: Exception Handling

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

If you were going to catch an exception of type Exception,where should this catch block be placed within your code?

Free
(Essay)
4.8/5
(40)
Correct Answer:
Verified

Catching an exception of type Exception is a very general exception,therefore it should be the last catch block in the series of catches,with the more specific exceptions being caught first.

Define an exception class called NegativeNumberException.The class should have a constructor with no parameters.If an exception is thrown with this zero-argument constructor,getMessage should return "Negative Number Not Allowed!" The class should also have a constructor with a single parameter of type String.If an exception is thrown with this constructor,then getMessage returns the value that was used as an argument to the constructor.

Free
(Essay)
4.7/5
(35)
Correct Answer:
Verified

public class NegativeNumberException extends Exception { public NegativeNumberException() { super("Negative Number Detected!"); } public NegativeNumberException(String message) { super(message); } }

When defining your own exception class,you extend an existing exception class.This is an example of:

Free
(Multiple Choice)
4.9/5
(39)
Correct Answer:
Verified

C

Exceptions that must follow the Catch or Declare Rule are often called unchecked exceptions.

(True/False)
4.9/5
(43)

A ___________ block should immediately follow a try block.

(Multiple Choice)
4.9/5
(36)

When an exception is thrown,the code in the surrounding try block continues executing and then the catch block begins execution.

(True/False)
4.8/5
(35)

The finally block contains code to be executed whether or not an exception is thrown in a try block.

(True/False)
4.8/5
(38)

All exceptions are descendants of the class:

(Multiple Choice)
4.8/5
(36)

What is the purpose of the method getMessage()when used with exception handling?

(Essay)
4.9/5
(44)

Methods that process String arguments as if they were numbers could possibly throw a/an _________ exception.

(Multiple Choice)
5.0/5
(32)

What is the catch or declare rule?

(Essay)
4.8/5
(27)

The throw operator causes a change in the flow of control.

(True/False)
4.9/5
(33)

Use a catch block to display the exception thrown in number two above.

(Essay)
4.9/5
(36)

An exception is caught in a _________ block.

(Multiple Choice)
4.8/5
(35)

Write a Java statement that throws a new exception with the String: Disk drive not ready.

(Essay)
4.9/5
(41)

Use a catch block to display the exception thrown in number one above.

(Essay)
4.8/5
(29)

The catch block has ________ parameters.

(Multiple Choice)
4.9/5
(31)

The basic way of handling exceptions in Java consists of the try-catch-throw trio.

(True/False)
4.9/5
(43)

You can not place a try block and its following catch blocks inside a larger try block or inside a larger catch block.

(True/False)
4.8/5
(34)

Which circumstance is an exception to the catch or declare rule?

(Multiple Choice)
4.9/5
(32)
Showing 1 - 20 of 45
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)