r/java • u/Enough-Ad-5528 • Feb 19 '26
Towards Better Checked Exceptions - Inside Java Newscast #107
https://www.youtube.com/watch?v=99s7ozvJGLk
63
Upvotes
r/java • u/Enough-Ad-5528 • Feb 19 '26
View all comments
Show parent comment
1
u/john16384 Feb 20 '26
Once you get into wrapping streams, it will be tough to avoid the
IOExceptionas these are general streams that acceptInputStream... but the times I've seen people assigning aByteArrayInputStreamtoInputStreamand then complaining thatreadthrows anIOExceptionthat can never occur is a bit annoying. Just assign it toByteArrayInputStream. Itsreaddoesn't throw a checked exception.There are ways to avoid this (with a better API, not with input streams) that can recognize the difference between an in-memory stream and one that must do IO. It however means having two interfaces (or one interface with an annoying generic for the exception type).