This chapter covers
- Controlling the behavior of your code in the face of errors and exceptions
- How error handling relates to the concept of structured concurrency
- Writing code that behaves correctly when parts of your system fail
- Writing unit tests for concurrent Kotlin code
- Using the specialty test dispatcher to speed up test execution and testing fine-grained concurrency constraints
- Testing flows with the Turbine library
Over the last few chapters, you’ve gotten an overview of the different aspects involved when writing concurrent code with Kotlin coroutines. To ensure the robustness of your applications, there is one more aspect that needs to be covered: How does your code behave when things go wrong?
Working with concurrent applications is an inherently complex task—likely, you’ll have many moving parts in your system that interact with each other. Beyond that, your application likely also interacts with other systems outside of your control. These systems may fail, or your connection to these services may be unreliable. However, even in these situations, your application should work well. One of the key aspects that enables this is proper error handling—implementing appropriate mechanisms to handle problems gracefully.