私はRxJava1を理解し始めています(今はRxJava2にならないようにしましょう)。RxJavaのチェック例外の処理
私は以下のようなコードをしました:
MoviesAPI.findMovieURLsByType("comedy")
.map(s -> {
try {
return potentialCheckedException(s); //Throws CheckedException
} catch (MyExceptionType ex) {
return Exceptions.propagate(ex);
}
})
.subscribe(new Subscriber<String>() {
public void onCompleted() {
System.out.println("------Completed!-------");
}
public void onError(final Throwable e) {
System.out.println(e.getMessage());
}
public void onNext(final String s) {
System.out.println(s);
}
});
私は以下のようなコンパイルエラーを取得:
Error:(28, 17) java: no suitable method found for subscribe(<anonymous rx.Subscriber<java.lang.String>>)
method rx.Observable.subscribe(rx.functions.Action1<? super java.io.Serializable>) is not applicable
(argument mismatch; <anonymous rx.Subscriber<java.lang.String>> cannot be converted to rx.functions.Action1<? super java.io.Serializable>)
method rx.Observable.subscribe(rx.Observer<? super java.io.Serializable>) is not applicable
(argument mismatch; <anonymous rx.Subscriber<java.lang.String>> cannot be converted to rx.Observer<? super java.io.Serializable>)
method rx.Observable.subscribe(rx.Subscriber<? super java.io.Serializable>) is not applicable
(argument mismatch; <anonymous rx.Subscriber<java.lang.String>> cannot be converted to rx.Subscriber<? super java.io.Serializable>)
method rx.Observable.<T>subscribe(rx.Subscriber<? super T>,rx.Observable<T>) is not applicable
(cannot infer type-variable(s) T
(actual and formal argument lists differ in length))
私は、その後、try-catchブロックを削除し、noPotentialCheckedException(s)
言うとpotentialCheckedException(s)
を交換した場合コンパイルエラーが消えます。どうして?私は何が欠けているのですか? Exceptions.propagate(ex)
を使用してCheckedException
をラップしていませんか?
ありがとうございます。
愚かな私。ありがとう@akarnokd。私はRxJavaで何が欠けているのか疑問に漂っていました.RxJavaは実際にJavaの基本にまで沸き立っています。 – karthiks