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

You may also like

AI
ChatGPT 5.5 and Codex Feel Like a Real Step Up
April 24, 2026
Programming
#PHPUK2010 Part 1
February 26, 2010
Programming
C# MySqlDataReader – “one line” function to return a row as an instance of a class.
September 18, 2013
AI
Android Studio Agent Skills Are Repo Instructions That Agents Might Actually Read
June 9, 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