Consider the following code :
public static void main(String[] args) {
try {
observableTesting();
} catch (Exception ex) {
System.out.println("Exception propagated : " + ex.getLocalizedMessage());
}
}
private static void observableTesting() throws Exception{
Observable.fromCallable(() -> { throw new Exception("TEST"); })
.subscribe(
next -> {},
error ->
{
System.out.println("Error : " + error.getLocalizedMessage());
throw new Exception(error);
}
);}
I would expect this to throw an exception and to propagate it to the calling function. This doesn't seem to produce the desirable effect.
As a workaround, I currently have to assign the error and throw it at the end of the function.
Are there any better ways to convert observable errors into exceptions?