rx-javaobservablesubscribedisposable

RxJava - Can I Bypass onSuccess and only have an onError option?


I am creating a Disposable:

myDisposable = myObservableMethod().subscribe(this::mySuccess, this::myError);

In this case, if myObservableMethod() returns a success, there is nothing more that I need to do, so mySuccess() is and empty method and exists for no reason.

I have tried this:

myDisposable = myObservableMethod().doOnError(this::myError).subscribe();

but am getting crashes.

Is there anyway to call this without needing an onSuccess ?


Solution

  • You have crash because you don't handle the error, exception is thrown to the upper level and crashes with unhandling exception.

    You could place empty lambda in place

    ... subscribe(ignore -> {}, this::myError)