Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Reduce number of exceptions thrown #81

Closed
twyatt opened this issue Aug 11, 2020 · 4 comments
Closed

Reduce number of exceptions thrown #81

twyatt opened this issue Aug 11, 2020 · 4 comments
Milestone

Comments

@twyatt
Copy link
Member

twyatt commented Aug 11, 2020

Instead, we should favor nullable return types or sealed classes.

http://www.douevencode.com/articles/2018-09/kotlin-error-handling/ summarizes it well.

Exceptions currently (develop branch) being thrown:

core

  • RemoteException
  • ConnectionLostException
  • OutOfOrderGattCallbackException
  • GattErrorStatusException

keep-alive

  • NotReadyException

throw

  • GattStatusException
  • RemoteException
  • ConnectionLostException
@twyatt twyatt added this to the 1.0.0 milestone Aug 11, 2020
@twyatt
Copy link
Member Author

twyatt commented Aug 13, 2020

Investigating this further, Roman Elizarov provided a great decision chart:

  1. Are callers of your API supposed to handle failures is some specific way on each call site or are they supposed to handle them globally together with other failures (crash app, write to log, show error dialog, etc)? If only globally - use exceptions, otherwise see below
  2. Do callers need additional domain-specific data about failure to handle it (failure position, failure type, etc) or just an indication that an operation has failed? If just an indication of failure - use nullable types, otherwise see below
  3. For locally-handled failures with domain-specific additional failure data create a domain-specific sealed class hierarchy to represent successful and failed results with the corresponding data vals.

P.S. Sometimes it varies by caller of your API, so extremely widely-used libraries might have several versions of the same function for different uses (see String.toInt and String.toIntOrNull in the standard library for example).

https://kotlinlang.slack.com/archives/C0922A726/p1536388784000100?thread_ts=1536360062.000100&cid=C0922A726

@twyatt
Copy link
Member Author

twyatt commented Aug 20, 2020

Further guidance:

exceptions

https://kotlin.christmas/2019/17

@twyatt
Copy link
Member Author

twyatt commented Aug 28, 2020

Opted to organize the exceptions thrown to make it clearer which exceptions are recoverable (#84).

May revisit/consider domain-specific Result returns in a later major version.

@twyatt twyatt modified the milestones: 1.0.0, 0.8.0-dev Sep 12, 2020
@twyatt twyatt modified the milestones: 0.8.0-dev, 0.8.0 Nov 2, 2020
@twyatt
Copy link
Member Author

twyatt commented Nov 2, 2020

Exceptions have been updated and changes are in 0.8.0 release.

@twyatt twyatt closed this as completed Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant