Java Exceptions: 19 MCQs with answers

All 19 multiple-choice questions from this kit, free and with no sign-up.

Warm-up · 10 questions

Q1. Which keyword is used to manually throw an exception in Java?

Beginner
A try B catch C throws D throw
Show answer & explanation

throw

The `throw` keyword is used to explicitly throw an exception, while `throws` declares exceptions in a method signature.

Q2. What is the superclass of all exceptions in Java?

Beginner
A Throwable B Error C Exception D RuntimeException
Show answer & explanation

Throwable

`Throwable` is the root class for the exception hierarchy; `Exception` and `Error` both extend it.

Q3. What happens if an exception is not caught in a Java program?

Beginner
A The exception is ignored B The program continues normally C The program restarts D The program terminates abruptly
Show answer & explanation

The program terminates abruptly

An uncaught exception propagates up the call stack and causes the program to terminate with an error message.

Q4. Which block is always executed regardless of whether an exception occurs or not?

Beginner
A catch B finally C try D throw
Show answer & explanation

finally

The `finally` block is designed to execute cleanup code and always runs after the `try`/`catch` blocks, unless the JVM exits.

Q5. What is the purpose of the `try` block?

Beginner
A To enclose code that might throw an exception B To always execute code C To handle exceptions D To declare exceptions
Show answer & explanation

To enclose code that might throw an exception

The `try` block wraps code that may throw an exception, allowing it to be caught and handled by a `catch` block.

Q6. Which of the following is NOT a type of exception in Java?

Beginner
A Checked exception B Unchecked exception C Runtime exception D Compile-time exception
Show answer & explanation

Compile-time exception

Java categorizes exceptions into checked and unchecked (runtime) exceptions; there is no 'compile-time exception' category.

Q7. Which exception is thrown when an array index is out of bounds?

Beginner
A IndexOutOfBoundsException B IllegalArgumentException C ArrayStoreException D ArrayIndexOutOfBoundsException
Show answer & explanation

ArrayIndexOutOfBoundsException

`ArrayIndexOutOfBoundsException` is thrown when accessing an array with an illegal index (negative, equal to size, or greater).

Q8. What is the purpose of the `getMessage()` method in an exception object?

Beginner
A To print the stack trace B To return a detailed message about the exception C To rethrow the exception D To suppress the exception
Show answer & explanation

To return a detailed message about the exception

`getMessage()` returns the detail message string of the exception, which often provides information about the cause.

Q9. A `finally` block is optional in a try-catch construct.

Beginner
A True B False
Show answer & explanation

True

A `finally` block is not required; you can have a try-catch without it. However, if present, it always executes.

Q10. Checked exceptions are checked at runtime.

Beginner
A True B False
Show answer & explanation

False

Checked exceptions are checked at compile time; the compiler ensures they are either caught or declared. Runtime exceptions are unchecked.

Building up · 8 questions

Q11. Which of the following is an unchecked exception?

Intermediate
A ArithmeticException B SQLException C ClassNotFoundException D IOException
Show answer & explanation

ArithmeticException

`ArithmeticException` is a subclass of `RuntimeException`, making it unchecked. The others are checked exceptions.

Q12. Which of the following correctly declares that a method might throw an IOException?

Intermediate
A public void readFile() throws IOException B public void readFile() catch IOException C public void readFile() throw IOException D public void readFile() finally IOException
Show answer & explanation

public void readFile() throws IOException

The `throws` keyword is used in the method signature to declare that the method may throw a checked exception like IOException.

Q13. Which of the following is a checked exception?

Intermediate
A ArrayIndexOutOfBoundsException B FileNotFoundException C ArithmeticException D NullPointerException
Show answer & explanation

FileNotFoundException

`FileNotFoundException` is a subclass of `IOException`, which is a checked exception. The others are unchecked runtime exceptions.

Q14. What does the `finally` block ensure?

Intermediate
A That exceptions are caught B That the program ends normally C That no exception is thrown D That cleanup code runs
Show answer & explanation

That cleanup code runs

The `finally` block is used for cleanup activities like closing resources, and it runs regardless of whether an exception is thrown or caught.

Q15. Which class is the parent of `RuntimeException`?

Intermediate
A Exception B Object C Throwable D Error
Show answer & explanation

Exception

`RuntimeException` extends `Exception`, which in turn extends `Throwable`.

Q16. What is the output of the following code? ```java try { int x = 10 / 0; } catch (ArithmeticException e) { System.out.println("Caught"); } finally { System.out.println("Finally"); } ```

Intermediate
A Caught B Compilation error C Finally D Caught Finally
Show answer & explanation

Caught Finally

The `ArithmeticException` is caught, printing "Caught", and then the `finally` block runs, printing "Finally".

Q17. Which keyword is used to handle multiple exceptions in a single catch block?

Intermediate
A || B && C & D |
Show answer & explanation

|

Java 7+ allows catching multiple exception types in one catch block using the pipe symbol `|`, e.g., `catch (IOException | SQLException e)`.

Q18. What is the difference between `throw` and `throws`?

Intermediate
A `throw` is used to throw an exception, `throws` declares exceptions in a method signature B `throw` is used in a method body, `throws` is used in a catch block C `throw` is for checked exceptions, `throws` is for unchecked D There is no difference
Show answer & explanation

`throw` is used to throw an exception, `throws` declares exceptions in a method signature

`throw` is a statement that actually throws an exception object, while `throws` is a clause in the method signature indicating which exceptions the method may throw.

Topper level · 1 questions

Q19. What happens if a `finally` block contains a `return` statement?

Advanced
A The program throws an exception B The return value from the try block is used C The return value from the finally block overrides the try block's return D A compilation error occurs
Show answer & explanation

The return value from the finally block overrides the try block's return

If a `finally` block has a `return`, it will override any return value from the `try` or `catch` blocks, which can be surprising.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages