Kotlin Coroutines: Catching `Exception` Breaks Structured Cancellation

Broad `catch (e: Exception)` swallowed `CancellationException`, preventing parent job cancellation.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: Kotlin Coroutines Platform: Java
Common Root Causes:
  • Broad `catch (e: Exception)` swallowed `CancellationException`, preventing parent job cancellation.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Always rethrow `CancellationException` (`if (e is CancellationException) throw e`).
Safe Diagnostic Command:
Audit try/catch blocks inside suspend functions
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Broad `catch (e: Exception)` swallowed `CancellationException`, preventing parent job cancellation. Recommended diagnostic: `Audit try/catch blocks inside suspend functions`. Remediation: Always rethrow `CancellationException` (`if (e is CancellationException) throw e`).

Worked Examples

  • Run `Audit try/catch blocks inside suspend functions` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-kotlin-coroutine-cancellation-swallowed · Independently verified: 2026-11-25

Related Resources