Skip to content

Commit

Permalink
Terminate the process in case of an unhandled exception
Browse files Browse the repository at this point in the history
Fixes #2398
  • Loading branch information
mvicsokolova committed Jul 2, 2021
1 parent 9d03705 commit 049fa26
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
package kotlinx.coroutines

import kotlin.coroutines.*
import kotlin.system.exitProcess
import kotlin.native.*
import kotlin.native.concurrent.*

internal actual fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable) {
// log exception
// println("Exception in \"${Worker.current}\"")
// exception.printStackTrace()
// todo: printing exception does not make it easy to debug (no source location), so let it crash instead
throw exception
// Use unhandled exception hook if it is set, otherwise print the stacktrace
val hook = setUnhandledExceptionHook({ _: Throwable -> }.freeze())
if (hook != null) hook(exception) else exception.printStackTrace()
// Terminate the process
exitProcess(-1)
}

0 comments on commit 049fa26

Please sign in to comment.