How do y'all deal with rx java terminating when th...
# rx
i
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
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
okay. You probably write extensions for
Observable<Result>
too to make things more convenient?
a
I haven't done that, but it sounds like a fine idea.
i
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
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.
i
you do have a point @alexsullivan114 ­čĹŹ