Move unhandledExceptionHook to kotlin code (#4704)
This commit is contained in:
committed by
Vasily Levchenko
parent
3ee0dc112b
commit
d5ca285a79
@@ -6,31 +6,17 @@ import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
fun setHookLegacyMM(hook: ReportUnhandledExceptionHook) : ReportUnhandledExceptionHook? {
|
||||
fun main(args : Array<String>) {
|
||||
assertFailsWith<InvalidMutabilityException> {
|
||||
setUnhandledExceptionHook { _ -> println("wrong") }
|
||||
}
|
||||
|
||||
return setUnhandledExceptionHook(hook.freeze())
|
||||
}
|
||||
|
||||
fun setHookNewMM(hook: ReportUnhandledExceptionHook) : ReportUnhandledExceptionHook? {
|
||||
return setUnhandledExceptionHook(hook)
|
||||
}
|
||||
|
||||
fun setHook(hook: ReportUnhandledExceptionHook) : ReportUnhandledExceptionHook? {
|
||||
return when (kotlin.native.Platform.memoryModel) {
|
||||
kotlin.native.MemoryModel.EXPERIMENTAL -> setHookNewMM(hook)
|
||||
else -> setHookLegacyMM(hook)
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val x = 42
|
||||
val old = setHook {
|
||||
val old = setUnhandledExceptionHook({
|
||||
throwable: Throwable -> println("value $x: ${throwable::class.simpleName}")
|
||||
}
|
||||
}.freeze())
|
||||
|
||||
assertNull(old)
|
||||
|
||||
throw Error("an error")
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val p: Nothing = error("FAIL")
|
||||
|
||||
fun main() {
|
||||
println("in kotlin main")
|
||||
}
|
||||
Reference in New Issue
Block a user