Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there inner exception concept in java

Tags:

.Net's exception can contain inner exceptions? I want to know if Java has similar thing or not?

like image 453
user496949 Avatar asked Mar 09 '11 11:03

user496949


People also ask

What are inner exceptions?

An inner exception is the exception that caused the current exception. It is used in cases when you want to surface a different exception than the one that your code caught but you don't want to throw away the original context.

What are the 3 types of exceptions?

There are three types of exception—the checked exception, the error and the runtime exception.

What is a nested exception in Java?

A nested exception is an exception that occurs while another exception is being handled. When this happens, the processing of the first exception is temporarily suspended.

Can we have try inside try?

In Java, we can use a try block within a try block. Each time a try statement is entered, the context of that exception is pushed on to a stack.


1 Answers

Absolutely - you can retrieve the inner exception (the "cause") using Throwable.getCause(). To create an exception with a cause, simply pass it into the constructor. (Most exceptions have a constructor accepting a cause, where it makes sense.)

like image 104
Jon Skeet Avatar answered Oct 05 '22 03:10

Jon Skeet