[K/N] Refactor unhandled exception handling API
* Do not reset unhandled exception hook * Add processUnhandledException to perform default unhandled exception processing * Add terminateWithUnhandledException to report the unhandled exception and terminate the program * Use the default unhandled exception processing in entrypoint, interop boundaries and in Worker.executeAfter * Add -Xworker-exception-handling to control exception processing of Worker.executeAfter. By default its the old behaviour with the old MM, and new behaviour with the new MM.
This commit is contained in:
committed by
Space
parent
766857881a
commit
7e04bb4bf1
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun main() {
|
||||
val exceptionHook = { _: Throwable ->
|
||||
println("Hook")
|
||||
}.freeze()
|
||||
|
||||
val oldHook = setUnhandledExceptionHook(exceptionHook)
|
||||
assertNull(oldHook)
|
||||
val hook1 = getUnhandledExceptionHook()
|
||||
assertEquals(exceptionHook, hook1)
|
||||
val hook2 = getUnhandledExceptionHook()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
data class C(val x: Int)
|
||||
|
||||
fun main() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
|
||||
val c = C(42)
|
||||
setUnhandledExceptionHook({ _: Throwable ->
|
||||
println("Hook ${c.x}")
|
||||
}.freeze())
|
||||
|
||||
throw Error("an error")
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun customExceptionHook(throwable: Throwable) {
|
||||
println("Hook called")
|
||||
assertEquals(::customExceptionHook, getUnhandledExceptionHook())
|
||||
}
|
||||
|
||||
fun main() {
|
||||
setUnhandledExceptionHook((::customExceptionHook).freeze())
|
||||
|
||||
throw Error("some error")
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun main() {
|
||||
setUnhandledExceptionHook({ t: Throwable ->
|
||||
println("Hook called")
|
||||
terminateWithUnhandledException(t)
|
||||
}.freeze())
|
||||
|
||||
throw Error("some error")
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun main() {
|
||||
setUnhandledExceptionHook({ t: Throwable ->
|
||||
println("Hook called")
|
||||
terminateWithUnhandledException(t)
|
||||
}.freeze())
|
||||
|
||||
val exception = Error("some error")
|
||||
processUnhandledException(exception)
|
||||
println("Not going to happen")
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun customExceptionHook(throwable: Throwable) {
|
||||
println("Hook called")
|
||||
throw Error("another error")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
setUnhandledExceptionHook((::customExceptionHook).freeze())
|
||||
|
||||
throw Error("some error")
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun main() {
|
||||
val called = AtomicInt(0)
|
||||
setUnhandledExceptionHook({ _: Throwable ->
|
||||
called.value = 1
|
||||
}.freeze())
|
||||
|
||||
val exception = Error("some error")
|
||||
processUnhandledException(exception)
|
||||
assertEquals(1, called.value)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
val exception = Error("some error")
|
||||
terminateWithUnhandledException(exception)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
val exception = Error("some error")
|
||||
processUnhandledException(exception)
|
||||
}
|
||||
Reference in New Issue
Block a user