Reputation: 5660
I have never seen any example where an IO Exception during java io operation was thrown. Each and every time I have seen it being caught. Is it true that for all practical purposes it never needs to be thrown ? If my answer to my previous question is untrue, then under which real life scenario is it ever thrown
?
Upvotes: 0
Views: 58
Reputation: 328735
Well yes, say for example a user just clicked on a "Show Orders" button and here is the code:
List<Order> orders = getOrdersFromDatabase();
showOrdersInTable(orders);
public List<Order> getOrdersFromDatabase() throws IOException {... }
Unfortunately, some stupid guy just decided to cut the power cable of the server for fun (OK: he just got fired). The server running the database is now unreachable.
Your code can either:
showPopup("Sorry, the server xyz can't be reach right now, do you want to retry or abort?");
Upvotes: 1
Reputation: 121780
When you talk about IOException
you also talk about all exceptions inherinting it. Among them, for instance, there is FileNotFoundException
(old file API -- ditch) but also ReadOnlyFilesystemException
, NotDirectoryException
, AccessDeniedException
, etc etc (new file API -- use).
Therefore, yes, a lot of IOException
s are thrown, in fact.
Upvotes: 1