Learning Android Development
Beyond Basic RxJava Error Handling
Beware! Not all errors are sent to onError!
Published in
8 min readMay 8, 2020
Most who knows RxJava would love it because of its ability in encapsulating Error Handling on onError
callback as shared in the blog below.
A simple example as below.
Single.just(getSomeData())
.map { item -> handleMap(item) }
.subscribe(
{ result -> handleResult(result) },
{ error -> handleError(error) } // Expect all error capture
)
A quick thought would be, ya, all crash will be handled by handleError(error)
call.
But it is not true!
1. Crashes on just()
Let’s start with something simple. Let’s say if the error crashes within getSomeData()
Single.just(getSomeData() /**🔥Crash🔥**/ )
.map { item -> handleMap(item) }
.subscribe(
{ result -> handleResult(result) },
{ error -> handleError(error) } // Crash NOT caught ⛔️
)