|
|
|
|
|
by bArray
2379 days ago
|
|
> You are right, but you still have to catch the checked > IOException. Rather than which alternative? There are tonnes of IO errors that can occur and are captured in Java that you may not ever even consider. IO is exceptionally tough and programmers should be aware that there could be 1 of a possible million reasons for failure, even if they don't care exactly why. It's not a massive ask either: try{
/* Perform some IO that 99.999999% of the time */
}catch(Exception e){
/* Something went wrong and we don't know the state of the disk */
}
Personally I believe applications should have their own wrapper around IO and handle it accordingly. I.e. not caring, re-trying, show-stopper, etc, etc.A lot of code I've written will have the following if I really don't care if it works or not: try{
/* IO code */
}catch(Exception e){
/* Do nothing */ // <-- Let others know that this was on purpose
}
|
|
That said, even if typed checked exception handling is important...it quickly becomes untenable.
You might try to abstract this But what if "..." potentially throws IOException? What if it potentially throws IOException or AWTException?You have to give up all your exception type safety to make an abstraction like withThing. It's just not composable.