This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling – 2”.
1. Which of the following keywords is used for throwing exception manually?
a) finally
b) try
c) throw
d) catch
View Answer
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?
a) RuntimeException
b) Error
c) Exception
d) ParentException
View Answer
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?
a) Catchable
b) RuntimeExceptions
c) String
d) Throwable
View Answer
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?
a) thrown
b) alloc
c) malloc
d) new
View Answer
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 a calling function to handle exception thrown by a called function?
a) throws
b) throw
c) try
d) catch
View Answer
Explanation: In Java, the “try” keyword is used in conjunction with the “catch” and/or “finally” blocks to handle exceptions. The “try” block contains the code that may potentially throw an exception. If an exception is thrown within the “try” block, it is caught and handled by the corresponding “catch” block.
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
View Answer
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?
a) finally
b) try
c) catch
d) throw
View Answer
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
View Answer
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.
a) True
b) False
View Answer
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 language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Java Internship
- Apply for Computer Science Internship
- Check Programming Books
- Check Java Books
- Practice Information Technology MCQs