logo

APSU Notes


Quiz 5

Question 1

Which of the following classes is for an exception that does not need to be caught in a catch block or declared in a throws clause?

RuntimeException

Question 2

If you are going to insert a throw statement in your code it is probably best to use the built-in Exception class rather than building your own

False

Question 3

Which of the following is the correct method heading for a method called doSomething that throws an exception called SomethingWentWrongException?

1
public void doSomething() throws SomethingWentWrongException

Question 4

A method that does handle an exception that it throws must have a throws clause in its heading.

True

Question 5

When is a finally block executed?

Both of the above.

Question 6

What is an exception?

An object that signals the occurrence of an unusual event.

Question 7

Java provides several predefined exception classes.

True

Question 8

What happens if an exception is thrown by a statement inside a try block?

The remainder of the try block is skipped and then the code in the catch block is executed

Question 9

What happens if an no exceptions are thrown inside a try block?

The code in the try block is executed and then the code in the catch block is skipped.

Question 10

If the statement data.saveToFile() throws a FileNotFoundException, which of the following is the correct way to handle this?

1
2
3
4
5
6
7
8
9
10
try
{
  // some code
  data.saveToFile();
  // more code
}
catch (FileNotFoundException e)
{
  // code to handle FileNotFoundException
}

Question 11

A try block must have a corresponding catch block

True

Question 12

Which of the following is the correct to declare a new exception class called BadStuffHappenedException?

1
2
3
4
public class BadStuffHappenedException extends Exception
{
  // Constructors
}

Notes

Quiz 7, Chapter 3/Exception