Java Interview Questions – Error and Exception Handling

  • What is Exception chaining in Java?

One of the important exception handling concept in Java when a different exception is thrown in response to an actual exception. This in turn will create a chain of exceptions. This is commonly used to wrap a checked exception to unchecked exception under various scenarios and such coding prevails when actually writing a framework in which case a known checked exception is thrown as an unchecked framework exception. Even though new exception is thrown, as a best practise always include the root cause (exception) in the newly created exception class.

  • With regards to JDK7 there is a new feature with regards to Exception handling. Can you detail this?

There are numerous small and medium new features on JDK7 which are very useful. Some of them with regards to error and exception handling is as detailed below:-

    • Multiple exception handling in one catch block

Reduces code cluttering and are more readable.

    •  ARM (Automatic Resource Management) blocks

As the name suggests it is capable of automatically handling resources on behalf of you, also known popularly as try with resource. Takes lot of botheration away from developers. Below is the example from oracle java docs:

Page Visitors: 1620

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

3 thoughts on “Java Interview Questions – Error and Exception Handling

Leave a Reply

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