Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public API to configure a default exception handler #3978

Open
swankjesse opened this issue Dec 8, 2023 · 1 comment
Open

Public API to configure a default exception handler #3978

swankjesse opened this issue Dec 8, 2023 · 1 comment

Comments

@swankjesse
Copy link

Use case

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.

package kotlinx.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

Prior Art

Java has this:

class Thread {
  public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler e)
  public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
}
swankjesse added a commit to cashapp/redwood that referenced this issue Dec 8, 2023
swankjesse added a commit to cashapp/redwood that referenced this issue Dec 8, 2023
* Install a global uncaught exception handler

* Reference a coroutines feature request

Kotlin/kotlinx.coroutines#3978
@dovchinnikov
Copy link
Contributor

Should be solved by #2932

@qwwdfsad qwwdfsad added the js label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants