250+ TOP MCQs on Exception Handling and Answers

This set of Java Questions and Answers for Experienced people on “Exception Handling”.

1. Which of the following keywords is used for throwing exception manually?
a) finally
b) try
c) throw
d) catch

Answer: c
Clarification: “throw’ keyword is used for throwing exception manually in java program. User defined exceptions can be thrown too.

2. Which of the following classes can catch all exceptions which cannot be caught?
a) RuntimeException
b) Error
c) Exception
d) ParentException

Answer: b
Clarification: Runtime errors cannot be caught generally. Error class is used to catch such errors/exceptions.

3. Which of the following is a super class of all exception type classes?
a) Catchable
b) RuntimeExceptions
c) String
d) Throwable

Answer: d
Clarification: Throwable is built in class and all exception types are subclass of this class. It is the super class of all exceptions.

4. Which of the following operators is used to generate instance of an exception which can be thrown using throw?
a) thrown
b) alloc
c) malloc
d) new

Answer: d
Clarification: new operator is used to create instance of an exception. Exceptions may have parameter as a String or have no parameter.

5. Which of the following keyword is used by calling function to handle exception thrown by called function?
a) throws
b) throw
c) try
d) catch

Answer: a
Clarification: A method specifies behaviour of being capable of causing exception. Throws clause in the method declaration guards caller of the method from exception.

6. Which of the following handles the exception when a catch is not used?
a) finally
b) throw handler
c) default handler
d) java run time system

Answer: c
Clarification: Default handler is used to handle all the exceptions if catch is not used to handle exception. Finally is called in any case.

7. Which part of code gets executed whether exception is caught or not?
a) finally
b) try
c) catch
d) throw

Answer: a
Clarification: Finally block of the code gets executed regardless exception is caught or not. File close, database connection close, etc are usually done in finally.

8. Which of the following should be true of the object thrown by a thrown statement?
a) Should be assignable to String type
b) Should be assignable to Exception type
c) Should be assignable to Throwable type
d) Should be assignable to Error type

Answer: c
Clarification: The throw statement should be assignable to the throwable type. Throwable is the super class of all exceptions.

9. At runtime, error is recoverable.
a) True
b) False

Answer: b
Clarification: Error is not recoverable at runtime. The control is lost from the application.

Java for Experienced people, here is complete set on Multiple Choice Questions and Answers on Java.

contest

Leave a Reply

Your email address will not be published. Required fields are marked *