I am new to Java, so I hope this is not trivial, but I really could not find what I am looking for.
I have a function that throws Exception:
public String foo(String s) throws MyException {
if ("a".equals(s)){
return s;
} else {
throw new MyException("Oh no!");
}
}
When MyException is just:
class MyException extends Exception{
String str1;
MyException(String str2) {
str1=str2;
}
public String toString(){
return ("MyException Occurred: "+str1) ;
}
}
Now I have another method that calls foo inside CompletableFuture:
private CompletableFuture<String> test() throws Exception{
return CompletableFuture.supplyAsync(() -> foo("b"));
}
But foo throws exception, so there is a compilation error here since the call for foo is unhandled exception.
All I want is to throw the original(inner) exception. How can I do that?