Description
Okio has @Throws(IOException)
annotations for most of its methods and also some documentation describing which exceptions could be thrown. However, some edge cases are not always documented.
For kotlinx-io
, I got rid of @Throws(IOException)
and want to explicitly document possible exceptions for every method.
Below are some open questions regarding exception-throwing policies.
-
What to throw on an attempt to read/write from a closed Source/Sink?
Okio throwsIlegalStateException
, while other libraries throw more IO-ish exceptions:java.io
throwsIOException
,java.nio
throwsClosedChannelException
, .NET'sSystem.IO.Stream
throwsObjectDisposedException
.
I would stick to throwingIOException
as users may expect IO exceptions when reading/wiring data and could handle it appropriately. -
What to throw for negative or too large
byteCount
values from methods accepting only it? What to throw from methods that also acceptoffset
?
For the latter, the library already throwsIndexOutOfBoundsException
which seems to be fine.
For other cases, it may throwIOOBE
orIllegalArgumentException
. It seems more appropriate to always throwIllegalArgumentException
in such cases.