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? Answer: c 2. Which of the following classes can catch all exceptions which cannot be caught? Answer: b 3. Which of the following is a super class of all exception type classes? Answer: d 4. Which of the following operators is used to generate instance of an exception which can be thrown using throw? Answer: d 5. Which of the following keyword is used by calling function to handle exception thrown by called function? Answer: a 6. Which of the following handles the exception when a catch is not used? Answer: c 7. Which part of code gets executed whether exception is caught or not? Answer: a 8. Which of the following should be true of the object thrown by a thrown statement? Answer: c 9. At runtime, error is recoverable. Answer: b Java for Experienced people, here is complete set on Multiple Choice Questions and Answers on Java.
a) finally
b) try
c) throw
d) catch
Clarification: “throw’ keyword is used for throwing exception manually in java program. User defined exceptions can be thrown too.
a) RuntimeException
b) Error
c) Exception
d) ParentException
Clarification: Runtime errors cannot be caught generally. Error class is used to catch such errors/exceptions.
a) Catchable
b) RuntimeExceptions
c) String
d) Throwable
Clarification: Throwable is built in class and all exception types are subclass of this class. It is the super class of all exceptions.
a) thrown
b) alloc
c) malloc
d) new
Clarification: new operator is used to create instance of an exception. Exceptions may have parameter as a String or have no parameter.
a) throws
b) throw
c) try
d) catch
Clarification: A method specifies behaviour of being capable of causing exception. Throws clause in the method declaration guards caller of the method from exception.
a) finally
b) throw handler
c) default handler
d) java run time system
Clarification: Default handler is used to handle all the exceptions if catch is not used to handle exception. Finally is called in any case.
a) finally
b) try
c) catch
d) throw
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.
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
Clarification: The throw statement should be assignable to the throwable type. Throwable is the super class of all exceptions.
a) True
b) False
Clarification: Error is not recoverable at runtime. The control is lost from the application.