Java Assertions Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of exception handling in Java with 15 questions covering exceptions, try-catch, finally, throw, throws, checked exceptions, unchecked exceptions, and custom exceptions.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. An event that disrupts the normal flow of program execution
An exception is an event that occurs during program execution and disrupts the normal flow of instructions.
A. try, catch, finally, throw, throws
Java provides try, catch, finally, throw, and throws as the main keywords for exception handling.
C. try
Code that may cause an exception is placed inside a try block so that it can be handled by an appropriate catch block.
B. catch
A catch block contains code that handles an exception thrown from the associated try block.
B. To execute cleanup code after try/catch processing
The finally block is generally used for cleanup actions and normally executes after the try/catch processing, including when control leaves those blocks.
B. throw
The throw keyword is used to explicitly throw a particular exception object.
B. To declare exceptions that a method may pass to its caller
The throws clause in a method declaration indicates checked exceptions that the method may propagate to its caller.
C. IOException
IOException is a checked exception, so code generally must catch it or declare it with throws.
A. Throwable
java.lang.Throwable is the superclass of both Exception and Error in Java's throwable hierarchy.
D. NullPointerException
NullPointerException extends RuntimeException, making it an unchecked exception.
B. It propagates to the calling method
If an exception is not handled in the current method, it can propagate up the call stack to the caller.
A. Yes
A try block can be followed by multiple catch blocks to handle different exception types.
B. Exception
A custom checked exception can be created by extending Exception directly or another checked exception type.
A. It creates and throws an IllegalArgumentException
The new expression creates an IllegalArgumentException object and throw transfers control by throwing that exception.
B. It separates exceptional error handling from normal program flow
Exception handling provides a structured way to detect and handle exceptional conditions without mixing all error-handling logic into normal program flow.