This set of Java Questions and Answers for Experienced people focuses on “Exception Handling”.
1. Which of the following keywords is used for throwing exception manually?
Explanation: “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?
Explanation: 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?
Explanation: 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?
Explanation: 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?
Explanation: 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?
b) throw handler
c) default handler
d) java run time system
Explanation: 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?
Explanation: 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
Explanation: The throw statement should be assignable to the throwable type. Throwable is the super class of all exceptions.
9. At runtime, error is recoverable.
Explanation: Error is not recoverable at runtime. The control is lost from the application.
Sanfoundry Global Education & Learning Series – Java Programming Language.
To practice all areas of Java for Experienced people, here is complete set on 1000+ Multiple Choice Questions and Answers on Java.