Skip to content

Decide on the behavior of the test module's global CoroutineExceptionHandler when it's not the only handler #3738

@dkhalanskyjb

Description

@dkhalanskyjb

To solve #1205, we changed runTest so that it installs a handler to catch all the exceptions flying through the coroutine machinery. However, it's not universally useful: in some elaborate scenarios, people have their own CoroutineExceptionHandler instances or override the default Thread.UncaughtExceptionHandler on the JVM. In these scenarios, we suddenly started intercepting exceptions that weren't in fact lost but were going to be processed further.

CoroutineExceptionHandler doesn't have the notion of priority, nor, currently, does it need one: only one CoroutineExceptionHandler can be installed in the CoroutineContext, and it's considered to process the exception, whereas when using CoroutineExceptionHandler as a ServiceLoader service, there's also no need for the notion of priority because, currently, all the handlers get notified, in addition to the platform-specific behavior always getting invoked.

Ideally, if a CoroutineExceptionHandler is installed already, the exception handler from the test module shouldn't get invoked, but it's unclear how to ensure that without special-casing the exact scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions