Java Questions & Answers – Exception Handling – 2

«
»

This set of Java Questions and Answers for Experienced people 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

Answer: c
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

Answer: b
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

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

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

Answer: d
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

Answer: d
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

Answer: c
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

Answer: a
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.
advertisement

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

Answer: c
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

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

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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.