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
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
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
A method that does handle an exception that it throws must have a throws clause in its heading.
True
When is a finally block executed?
Both of the above.
What is an exception?
An object that signals the occurrence of an unusual event.
Java provides several predefined exception classes.
True
What happens if an exception is thrown by a statement inside a try block?
The remainder of the
tryblock is skipped and then the code in thecatchblock is executed
What happens if an no exceptions are thrown inside a try block?
The code in the
tryblock is executed and then the code in thecatchblock is skipped.
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 }
A try block must have a corresponding catch block
True
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 }