Repository: Kotlin/kotlinx.coroutines
File: kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt (Kotlin)

Code before:
 * log the exception, show some kind of error message, terminate, and/or restart the application.
 *
 * If you need to handle the exception in a specific part of the code, it is recommended to use `try`/`catch` around
 * the corresponding code inside your coroutine. This way you can prevent completion of the coroutine
 * with the exception (exception is now _caught_), retry the operation, and/or take other arbitrary actions:
 *
 * ```
 * scope.launch { // launch child coroutine in a scope
 *     try {
 *          // do something
 *     } catch (e: Throwable) {
 *          // handle exception
 *     }
 * }
 * ```
 *
 * ### Uncaught exceptions with no handler
 *
 * When no handler is installed, an exception is handled in the following way:
 * - If the exception is [CancellationException], it is ignored, as these exceptions are used to cancel coroutines.
 * - Otherwise, if there is a [Job] in the context, then [Job.cancel] is invoked.
 * - Otherwise, as a last resort, the exception is processed in a platform-specific manner:
 *   - On JVM, all instances of [CoroutineExceptionHandler] found via [ServiceLoader], as well as
 *     the current thread's [Thread.uncaughtExceptionHandler], are invoked.
 *   - On Native, the whole application crashes with the exception.
 *   - On JS and Wasm JS, the exception is propagated into the JavaScript's runtime event loop
 *     and is processed in a platform-specific way determined by the platform itself.
 *
 * [CoroutineExceptionHandler] can be invoked from an arbitrary thread.
 */
public interface CoroutineExceptionHandler : CoroutineContext.Element {
    /**
     * Key for [CoroutineExceptionHandler] instance in the coroutine context.
     */
    public companion object Key : CoroutineContext.Key<CoroutineExceptionHandler>

    /**
     * Handles uncaught [exception] in the given [context]. It is invoked
     * if the coroutine has an uncaught exception.
     */
    public fun handleException(context: CoroutineContext, exception: Throwable)
}


Review comment (suggestion):
```suggestion
 *   - On JS and Wasm JS, the exception is propagated into the JavaScript runtime's event loop
```

Code after:
 * log the exception, show some kind of error message, terminate, and/or restart the application.
 *
 * If you need to handle the exception in a specific part of the code, it is recommended to use `try`/`catch` around
 * the corresponding code inside your coroutine. This way you can prevent completion of the coroutine
 * with the exception (exception is now _caught_), retry the operation, and/or take other arbitrary actions:
 *
 * ```
 * scope.launch { // launch child coroutine in a scope
 *     try {
 *          // do something
 *     } catch (e: Throwable) {
 *          // handle exception
 *     }
 * }
 * ```
 *
 * ### Uncaught exceptions with no handler
 *
 * When no handler is installed, an exception is handled in the following way:
 * - If the exception is [CancellationException], it is ignored, as these exceptions are used to cancel coroutines.
 * - Otherwise, if there is a [Job] in the context, then [Job.cancel] is invoked.
 * - Otherwise, as a last resort, the exception is processed in a platform-specific manner:
 *   - On JVM, all instances of [CoroutineExceptionHandler] found via [ServiceLoader], as well as
 *     the current thread's [Thread.uncaughtExceptionHandler], are invoked.
 *   - On Native, the whole application crashes with the exception.
 *   - On JS and Wasm JS, the exception is propagated into the JavaScript runtime's event loop
 *     and is processed in a platform-specific way determined by the platform itself.
 *
 * [CoroutineExceptionHandler] can be invoked from an arbitrary thread.
 */
public interface CoroutineExceptionHandler : CoroutineContext.Element {
    /**
     * Key for [CoroutineExceptionHandler] instance in the coroutine context.
     */
    public companion object Key : CoroutineContext.Key<CoroutineExceptionHandler>

    /**
     * Handles uncaught [exception] in the given [context]. It is invoked
     * if the coroutine has an uncaught exception.
     */
    public fun handleException(context: CoroutineContext, exception: Throwable)
}