For anyone who uses RxJava with Room, do you alway...
# android
g
For anyone who uses RxJava with Room, do you always error handle your subscriptions?
g
Depends what is your use case, uncaught exception will be propagated and crash by default, if it fine for you, then no need to add explicit error handler
g
Just reading and writing values, no manipulation in between. What kind of exceptions could I encounter?
g
not sure what you mean by “reading and writing values”, but if you do not expect any exceptions, do not add onError in subscription, in case of error it would crash, and probably it would be a right thing
But suppressing all uncaught exception would be very bad thing in such case
g
I guess what I'm wondering is if Room or SQLite itself can give exceptions at the beginning of the chain. I know that I can give myself potential exceptions by doing wacky things like taking a
Maybe
and
.flatMapSingle
which would end up in a
NoSuchElementException
if there is not value from the start.
If I'm doing nothing on the chain other than a
.subscribe
do I still need to handle a throwable?
So far, I haven't encountered anything despite having error handling everywhere -- which is making me wonder if I should bother in the first place.
Found a pretty good answer here https://stackoverflow.com/questions/53183023/android-room-exceptions but I don't know much more beyond that 🤷
g
You may have a lot of different sqlite error for queries, but chance of them is pretty low if you don’t have foregign keys or some complex logic
g
ah got it. I guess it's sort of "safe" to leave out some error handling for some really simple logic then
I recently switched a project over from using shared preference to Room, so there are a lot of simple operations everywhere, just reading and writing primitives. It's been a pain to error handle everything.
g
it really depends what is your expected behaviour in case of error, just crash with uncaught exception looks fine as default, so nothing bad do hot handle error case, it’s the same as not wrapping operation to try/catch
k
Can also have unexpected stuff like disk errors from file corruption. If the exception lands in the global exception handler, it's almost impossible to chase down...
g
Why does it impossible? It had original exception So if you do not ignore it, it shouldn't be a problem
k
The stack trace isn't great
g
Stack is fine, it has original exception as cause, if you get cause of unhandled exception it would be the same as get this exception in
onError