How do y'all deal with rx java terminating when there are errors? Is there a pattern for observables that shouldn't do this (one of them is probably using
Result
as return type)?
a
alexsullivan114
01/28/2020, 12:47 PM
I think error handling is one of the hardest things about RxJava. Wrapping potential errors in a
Result
or
Either
object is one approach that I often use.
i
iex
01/29/2020, 8:08 AM
okay. You probably write extensions for
Observable<Result>
too to make things more convenient?
a
alexsullivan114
01/29/2020, 12:30 PM
I haven't done that, but it sounds like a fine idea.
i
iex
01/29/2020, 1:19 PM
okay, thanks. Yeah, using
Result
seems to be the only way to circumvent the issues. It's weird that rx doesn't allow to fully recover from errors.
a
alexsullivan114
01/29/2020, 1:24 PM
I don't think it's as easy as you might imagine. Like, if you have some observables that's created like this:
Copy code
myObservable.create { emitter ->
emitter.onNext(1)
emitter.onNext(2)
throw new RuntimeException("Crash!")
}
How should rx allow you to "recover"? Something threw an error that wasn't caught. All it can do is basically let you catch it yourself (i.e. the
onError
block) or crash. It can't really just "continue" since an exception was thrown.