logo

APSU Notes


Quiz 7

Question 1

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
}

Question 2

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 3

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?

RuntimException

Question 4

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 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

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

True

Question 8

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 9

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 10

A try block must have a corresponding catch block

True

Question 11

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 12

Java provides several predefined exception classes.

True

Notes

Quiz 5, Chapter 3/Exception