.Net's exception can contain inner exceptions? I want to know if Java has similar thing or not?
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.
There are three types of exception—the checked exception, the error and the runtime exception.
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.
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With