Skip to content
Wade Womersley

wade.one

wade womersley – york based software engineer

  • Home
  • 2026
  • November
  • 3
  • Kotlin Cancellation Should Survive Your Error Handling

Kotlin Cancellation Should Survive Your Error Handling

Posted on November 3, 2026 By
Programming

Catching every exception around a coroutine can accidentally turn cancellation into an ordinary application failure. A screen closes, the job is cancelled, and a broad catch block decides to display an error or try again. The code is being helpful about work that was supposed to stop.

Kotlin’s cancellation guide explains that cancellation is cooperative and uses CancellationException. If you catch that exception while handling other failures, rethrow it so cancellation can continue through the coroutine machinery. The surrounding scope and the work inside it both need to participate.

For me, a useful check is to cancel the operation at a realistic point and observe what follows. Does the child work finish, are resources released, and does the closed screen stay closed? Testing only the successful return value leaves out the behaviour that matters when someone navigates away halfway through.

This does not need a complicated exception hierarchy. It needs error handling that distinguishes an operation failing from its owner no longer wanting it. Make that distinction visible, keep cleanup reliable, and resist turning every interrupted job into a fresh attempt. Sometimes the correct outcome is simply that the work stops.

Share:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Tags: cancellation coroutines kotlin

Post navigation

❮ Previous Post: HTTP 304 Means the Cached Copy Is Still Useful
Next Post: The Window Seat Turns a Train Journey Into a Very Long Establishing Shot ❯

You may also like

Gaming
Epic Games releases Unreal Development Toolkit for FREE
November 7, 2009
Programming
Hidden things, lack of fries and pointless data
September 4, 2009
Programming
C# 14 Extension Members Should Reduce Helper Class Noise
May 19, 2026
Programming
When I Recommend a Rewrite, and When I Absolutely Don’t
March 28, 2026
  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown