Recall & Review
beginner
What is a checked exception in Java?
A checked exception is an exception that the compiler forces you to handle. You must either catch it with a try-catch block or declare it with a throws clause in the method signature.
Click to reveal answer
beginner
What is an unchecked exception in Java?
An unchecked exception is an exception that the compiler does not force you to handle. These usually come from programming errors like null pointer access or array index out of bounds.
Click to reveal answer
beginner
Give an example of a checked exception.
Examples of checked exceptions include IOException, SQLException, and ClassNotFoundException. These often relate to external resources or conditions outside the program's control.
Click to reveal answer
beginner
Give an example of an unchecked exception.
Examples of unchecked exceptions include NullPointerException, ArrayIndexOutOfBoundsException, and IllegalArgumentException. These usually indicate bugs in the code.
Click to reveal answer
intermediate
Why does Java distinguish between checked and unchecked exceptions?
Java distinguishes them to encourage programmers to handle expected problems (checked exceptions) while not forcing handling of programming errors (unchecked exceptions), making code safer and clearer.
Click to reveal answer
Which of the following is a checked exception?
✗ Incorrect
IOException is a checked exception that must be handled or declared.
Unchecked exceptions are usually caused by:
✗ Incorrect
Unchecked exceptions often come from bugs like null pointer access or invalid arguments.
What must you do when a method throws a checked exception?
✗ Incorrect
You must either catch the checked exception or declare it in the method signature.
Which class is the root of unchecked exceptions?
✗ Incorrect
RuntimeException is the base class for unchecked exceptions.
If you forget to handle a checked exception, what happens?
✗ Incorrect
The compiler will give an error if a checked exception is not handled or declared.
Explain the difference between checked and unchecked exceptions in Java.
Think about compiler enforcement and typical causes.
You got /4 concepts.
Describe a real-life situation where you might encounter a checked exception and how you would handle it.
Imagine opening a file that might not exist.
You got /3 concepts.