Search Tutorials


Java Exception Handling MCQ - Multiple Choice Questions And Answers | JavaInUse

Java Exception Handling MCQ - Multiple Choice Questions And Answers

Q. What is an exception in Java?

A. An error in the code
B. A runtime issue
C. An unexpected event
D. All of the above

Q. Which keyword is used to handle exceptions in Java?

A. try
B. catch
C. throw
D. All of the above

Q. What does the finally block do in exception handling?

A. Handles the exception
B. Always executes whether an exception occurs or not
C. Follows the try block
D. All of the above

Q. What is the purpose of the try-with-resources statement in Java?

A. To catch exceptions
B. To release resources automatically
C. To handle multiple exceptions
D. To create checked exceptions

Q. Which keyword is used to explicitly throw an exception in Java?

A. try
B. catch
C. throw
D. finally

Q. Can multiple catch blocks be used for a single try block in Java?

A. No, only one catch block is allowed
B. Yes, but only for checked exceptions
C. Yes, for different types of exceptions
D. No, try block cannot catch exceptions

Q. What is the difference between checked and unchecked exceptions in Java?

A. Checked exceptions are caught at compile-time, while unchecked exceptions are caught at runtime
B. Checked exceptions are caught at runtime, while unchecked exceptions are caught at compile-time
C. Checked exceptions are explicitly declared in the code, while unchecked exceptions are not
D. Checked exceptions are related to I/O operations, while unchecked exceptions are related to logic errors

Q. When does a finally block not execute in Java?

A. When an exception occurs
B. When a catch block executes
C. When a return statement is encountered
D. Finally block always executes

Q. What is the purpose of the `throws` keyword in Java?

A. To catch exceptions
B. To declare checked exceptions
C. To throw exceptions
D. To handle exceptions

Q. Which exception class is the base class for all exceptions in Java?

A. RuntimeException
B. Exception
C. Throwable
D. Error

Q. Which of the following code snippets demonstrates the correct syntax for exception handling in Java?

A.
try {
    // code that may throw an exception
} catch (Exception e) {
    // catch the exception and handle it
}
B.
try {
    // code that may throw an exception
} catch (error e) {
    // catch the error and handle it
}
C.
try {
    // code that may throw an exception
} catch (Throwable t) {
    // catch any throwable and handle it
}
D.
try {
    // code that may throw an exception
} catch (RuntimeException e) {
    // catch only runtime exceptions and handle them
}





Q. Which of the following is true about checked and unchecked exceptions in Java?

A.
Checked exceptions are subclasses of Error class.
B.
Unchecked exceptions are subclasses of Exception class.
C.
Checked exceptions are required to be caught or declared.
D.
Unchecked exceptions are always fatal and cannot be recovered from.

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

A.
ArithmeticException
B.
NullPointerException
C.
InvalidInputException
D.
ArrayIndexOutOfBoundsException

Q. How can you handle multiple exceptions in a single catch block in Java?

A.
Use separate catch blocks for each exception.
B.
Use a finally block after the catch block.
C.
Use the throws keyword to specify multiple exceptions.
D.
Use a single catch block with multiple exception types separated by a pipe (|) symbol.

Q. What is the purpose of the finally block in try-catch-finally exception handling?

A.
To catch and handle exceptions.
B.
To specify the types of exceptions that can be thrown.
C.
To ensure that certain code is always executed, whether an exception occurs or not.
D.
To transfer control to a specific catch block.

Q. What happens if an exception is thrown in the catch block itself?

A.
The exception is caught and handled by the same catch block.
B.
The catch block is skipped, and the exception is caught by the next catch block (if any).
C.
The exception is caught by the catch block but is not handled.
D.
The exception is thrown further up the call stack.

Q. Which of the following is an unchecked exception in Java?

A.
IOException
B.
ClassNotFoundException
C.
RuntimeException
D.
SQLException

Q. What happens if an exception is thrown inside a finally block?

A.
The exception is caught and handled by the same finally block.
B.
The finally block is skipped, and the exception is caught by the next finally block (if any).
C.
The exception is caught by the finally block but is not handled.
D.
The exception is thrown further up the call stack.

Q. What is the purpose of the throws keyword in Java?

A.
To define a checked exception that a method may throw.
B.
To catch and handle exceptions.
C.
To specify the types of exceptions that can be caught by a catch block.
D.
To transfer control to a specific catch block.