In program of interest, during execution of a method() some HTTP related exceptions can occur. Due to something, that method was set to be able to throw ExpException. My interest is only in specific type of exception, i.e. UnknownHostException, which can be accessed by using
if (e.getCause().getCause().getCause() instanceof UnknownHostException)
which I hope you agree is very nasty way. Thus, this works fine:
public class ExportException extends Exception;
class sth{
method() throws ExpException;
}
class main{
try{
method()
} catch(ExpExceptione e){
if (e.getCause().getCause().getCause() instanceof UnknownHostException){
doSthElse();
}
}
However, I was hoping to do as described below. Unfortunately, Eclipse yells
Unreachable catch block for UnknownHostException. This exception is never thrown from the try statement.
Is there any help for me? I don't want to use getCause()^3.
An addition: this is a big big project and I'm the new newbie and would rather not mess with outside classes, but just the "main".
My program is something like:
public class ExportException extends Exception;
class sth{
method() throws ExpException;
}
class main{
try{
method()
} catch(UnknownHostException e){
doSth();
} catch(ExpExceptione){
doSthElse();
}