We can usually avoid the errors that result from passing inappropriate arguments to functions, or at least move them from inside the function to outside, where we probably have more context. Kotlin Value Classes (previously known as Inline Classes) are good for this, allowing us to create Tiny Types that are more restricted and expressive than primitives.
This is Part 30 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
• All Gilded Rose Episodes
and the code on GitHub https://github.com/dmcg/gilded-rose-tdd
This sub-series on error handling is also a playlist
• Kotlin Error Handling - Exceptions, N...
You can read more about tiny types and partial functions on my blog http://oneeyedmen.com/failure-is-not-...
As far as I can see, Darren Hobbs coined the term Tiny Types https://darrenhobbs.com/2007/04/11/ti...
If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook
http://java-to-kotlin.dev. Chapter 19 covers error handling.