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 }
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 thecatch
block is executed.
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
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 }
When is a finally
block executed?
Both of the above.
What is an exception?
An object that signals the occurrence of an unusual event.
A method that does handle an exception that it throws must have a throws
clause in its heading.
True
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
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
A try
block must have a corresponding catch
block
True
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 thecatch
block is skipped.
Java provides several predefined exception classes.
True