How to handle Java.net.UnknownHostException ?
martinrevert opened this issue · comments
Hi ahorn, this is isn't an issue but I'm looking to manage in a polite way any eventual network disconnections in my app when using android-rss.
Can you recommend me how to catch and handle this kind of exception. I was trying to manage it in my code but that exception is not throwed directly from my code. The main idea is to prevent my app to break with a message error, and handle it whit a polite message to the user.
Thank you in advance,
Martin
Use a try {... } catch(UnknownHostException e) { ... } block. As you've said, please only report bugs that are android-rss specific.
Kind regards,
Alex
I tried that on my activity, of course, but it give me errors because it must be done from where the network call happens and that try happens on android-rss library. I wonder why this kind of exception is not handled like an RSSReaderException too.
Anyway, thanks.
In RSSReader::load(String) (see [1]), every IOException is caught. Note that UnknownHostException is a subclass of IOException. After the IOException has been caught, it is rethrown (thrown again) as an RSSFault. RSSFault is a runtime exception. You can reliably catch these runtime exceptions through a "fault barrier". A thread-safe implementation of a fault barrier can be found in the concurrent-error-recovery project [2].
[1] https://github.com/ahorn/android-rss/blob/master/src/main/java/org/mcsoxford/rss/RSSReader.java#L128
[2] https://github.com/ahorn/concurrent-error-recovery