Closed
Description
Try the following code:
public static void main(final String[] args) {
Observable.fromArray(new String[]{"1","a","2"}).flatMapSingle(new Function<String, SingleSource<Integer>>() {
@Override
public SingleSource<Integer> apply(final String s) throws NumberFormatException {
//return Single.just(Integer.valueOf(s)); //This works
return Single.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws NumberFormatException {
return Integer.valueOf(s);
}
});
}
}).subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(final Disposable d) {
System.out.println("Subscribe");
}
@Override
public void onNext(final Integer value) {
System.out.println("Value: " + value);
}
@Override
public void onError(final Throwable e) {
System.out.println("Error: " + e);
}
@Override
public void onComplete() {
System.out.println("Complete");
}
});
}
The program will only output the Value 1, the NumberFormatException gets lost. If I were to use Single.just, the exception gets printed correctly.