Skip to content

Improve and explicitly document policies regarding exception throwing #138

Closed
@fzhinkin

Description

@fzhinkin

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.

  1. What to throw on an attempt to read/write from a closed Source/Sink?
    Okio throws IlegalStateException, while other libraries throw more IO-ish exceptions: java.io throws IOException, java.nio throws ClosedChannelException, .NET's System.IO.Stream throws ObjectDisposedException.
    I would stick to throwing IOException as users may expect IO exceptions when reading/wiring data and could handle it appropriately.

  2. What to throw for negative or too large byteCount values from methods accepting only it? What to throw from methods that also accept offset?
    For the latter, the library already throws IndexOutOfBoundsException which seems to be fine.
    For other cases, it may throw IOOBE or IllegalArgumentException. It seems more appropriate to always throw IllegalArgumentException in such cases.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions