• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

What is meant by Chained Exception ?

An application often responds to an Exception by throwing another Exception. In effect, the first Exception causes the second Exception. It can be very helpful to know when one Exception causes another.

- Chained Exceptions help the programmer do this.

The following are the methods and constructors in Throwable that support Chained Exceptions.

Throwable getCause()
Throwable initCause(Throwable)
Throwable(String, Throwable)

The Throwable argument to initCause and the Throwable constructors is the Exception that caused the current Exception. getCause returns the Exception that caused the current Exception, and initCause returns the current Exception.

Example :

try {

} catch (IOException e) {
throw new SampleException("Other IOException", e);

In this example, when an IOException is caught, a new SampleException Exception is created with the original cause attached and the chain of Exceptions is thrown up to the next higher level Exception handler.
Anchored Exceptions clinched alongside java. Anchored special case is utilized within such sort of circumstances. Constructors about Throwable class Which help anchored exceptions over java : Throwable(Throwable cause) :- the place result in will be the exemption that reasons those current special case.
Chained Exception is used in such type of situations. Constructors Of Throwable class Which support chained exceptions in java : Throwable(Throwable cause) :- Where cause is the exception that causes the current exception. Your all java basic to advanced level concepts and query will be solved by traininginlucknow. Advanced Java training in lucknow helps students to solve query related to java and advanced java concepts