Deferring Error Handling With A Kotlin Result Type

Опубликовано: 25 Февраль 2025
на канале: Pairing with Duncan
1,249
34

When an operation can proceed even when there has been an error we can: ignore it; log and continue; or return an error type.

Returning an error type allows us to defer deciding what to do about the error until later. In this episode we use a result as a property of our Item type, so that our rendering code has all the context to generate the desired HTML.

This is Part 48 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...  

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.