Which class is the superclass of all exceptions and errors?
Error and Exception both extend Throwable.
Exception Handling · Exercise 1 of 4
Twenty multiple-choice questions on Java exception handling: the hierarchy, checked and unchecked exceptions, try/catch/finally, multi-catch, throw and throws, custom exceptions, try-with-resources and assertions. Pick an option to check your answer instantly.
Which class is the superclass of all exceptions and errors?
Error and Exception both extend Throwable.
Which of these is a checked exception?
The others are RuntimeExceptions.
What must a method do with a checked exception that its code can throw?
This is the "catch or specify" requirement.
Which is an Error rather than an Exception?
Errors signal serious JVM problems that applications normally should not catch.
Which statement is correct?
throw new X(); versus void m() throws X.
When does a finally block run?
Only a JVM exit or a hang prevents it.
What happens to finally if try calls System.exit(0)?
This is the classic exception to "finally always runs".
In which order should catch blocks for FileNotFoundException, IOException and Exception appear?
Most specific first; otherwise the later blocks are unreachable.
Which multi-catch is legal?
The alternatives must not be related by subclassing.
Which form is legal?
A try needs at least one catch, a finally, or resources.
Timed online tests with instant scores and explanations.