You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Public API to configure a default exception handler #3978
I’m using Kotlin/JS. I’d like a public API to install a platform exception handler. As-is my uncaught exceptions are going to console.log, where they’re invisible to my observability tools. The ensurePlatformExceptionHandlerLoaded() function does what I want, but that function isn’t public!
I have tried to get my CoroutineExceptionHandler into every CoroutineContext in my application, but I’ve found it very difficult to stay on top of all of these. Especially with first- and third-party libraries that do their own coroutines things!
The Shape of the API
This multiplatform API addresses my request across all platforms.
packagekotlinx.coroutines/** * Invoked for uncaught exceptions thrown in CoroutineContexts that * don’t have a CoroutineExceptionHandler. * * If null, a platform-specific handler will be invoked instead.*/val defaultCoroutineExceptionHandler:CoroutineExceptionHandler?=null
Reacted by Norbert Sándor, Marcello Galhardo, Ji Sungbin, Victor Turansky, John Camp, drinkthestars, Marshall Mann-Wood, Ryan Nett, timemanx, Jonathon Chu and 3 more
@swankjesse, hi! An upcoming change addresses this: 6f0fb66
With it, when no platform-specific handler is installed, we will default to scheduling the error on the event loop of the JavaScript runtime. You will be able to install your own handler in the JavaScript code. For example, on Node/JS, it would be process.on('uncaughtException', function(e) { /* your handler here */ });.
Does this address the problem, or would the global exception handler in kotlinx.coroutines for JS still be useful?
Activity
Reference a coroutines feature request
Install a global uncaught exception handler (#1735)
dovchinnikov commentedon Dec 11, 2023
Should be solved by #2932
dkhalanskyjb commentedon Jul 28, 2025
@swankjesse, hi! An upcoming change addresses this: 6f0fb66
With it, when no platform-specific handler is installed, we will default to scheduling the error on the event loop of the JavaScript runtime. You will be able to install your own handler in the JavaScript code. For example, on Node/JS, it would be
process.on('uncaughtException', function(e) { /* your handler here */ });.Does this address the problem, or would the global exception handler in
kotlinx.coroutinesfor JS still be useful?swankjesse commentedon Jul 28, 2025
@dkhalanskyjb I think I can run with that!