Skip to content

uncaughtExceptionPreHandler does not exist #3215

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

Closed
NWuensche opened this issue Mar 4, 2022 · 4 comments
Closed

uncaughtExceptionPreHandler does not exist #3215

NWuensche opened this issue Mar 4, 2022 · 4 comments
Assignees
Labels
docs KDoc and API reference

Comments

@NWuensche
Copy link
Contributor

NWuensche commented Mar 4, 2022

I tried to implement a global coroutine exception handler. However, the uncaughtExceptionPreHandler from the wiki does not exist. I also added the kotlinx-coroutines-android lib in version 1.6, but I still don't get this. Is the wiki outdated, as the readme also does not say anything about uncaughtExceptionPreHandler nor Thread.uncaughtExceptionPreHandler?

@dkhalanskyjb dkhalanskyjb added the docs KDoc and API reference label Mar 9, 2022
@dkhalanskyjb
Copy link
Collaborator

The docs should be updated, as the implementation changed since then.

In any case, you shouldn't have to do anything, the docs only describe what our library does on its own. Adding kotlinx-coroutines-android as a dependency should be sufficient for uncaught exceptions in coroutines to be propagated to the Android runtime, one way or another.

@NWuensche
Copy link
Contributor Author

NWuensche commented Mar 9, 2022 via email

@qwwdfsad
Copy link
Member

We do not have option for that and we do not intend to provide one. Reactive frameworks experience showed us that having a global mutable state for dispatchers, error handlers, various on* hooks and shutdown hook is the very common source of non-deterministic bugs as the behaviour depends only on who is invoked first/last and has its Rx*Plugins.set* won.

The suggested solution is to have your own CEH in application-specific top-level scope.

@NWuensche
Copy link
Contributor Author

Thank you. However, maybe you shouldn't write "...it is possible to redefine global exception handler for all coroutines" in the documentation then, but maybe write that this is indeed not possible/recomended :) . I would also like it if you could give an example in the documentation on how to define a CEH on top-level scope. I work on Android, and I'm not 100% how to do this considering using the provided lifecycleScope and viewModelScope. It would be really annoying to add (and maybe forget) a CEH to each scope separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs KDoc and API reference
Projects
None yet
Development

No branches or pull requests

3 participants