[K/N] Allow to unset unhandled exception hook ^KT-49228
This commit is contained in:
committed by
Space
parent
187fe6d50a
commit
41d6dc5914
@@ -18,4 +18,9 @@ fun main() {
|
||||
val hook1 = getUnhandledExceptionHook()
|
||||
assertEquals(exceptionHook, hook1)
|
||||
val hook2 = getUnhandledExceptionHook()
|
||||
assertEquals(exceptionHook, hook2)
|
||||
val hook3 = setUnhandledExceptionHook(null)
|
||||
assertEquals(exceptionHook, hook3)
|
||||
val hook4 = getUnhandledExceptionHook()
|
||||
assertNull(hook4)
|
||||
}
|
||||
|
||||
@@ -57,6 +57,17 @@ public typealias ReportUnhandledExceptionHook = Function1<Throwable, Unit>
|
||||
* Hook must be a frozen lambda, so that it could be called from any thread/worker.
|
||||
*/
|
||||
@OptIn(FreezingIsDeprecated::class)
|
||||
public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook?): ReportUnhandledExceptionHook? {
|
||||
try {
|
||||
return UnhandledExceptionHookHolder.hook.swap(hook)
|
||||
} catch (e: InvalidMutabilityException) {
|
||||
throw InvalidMutabilityException("Unhandled exception hook must be frozen")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("CONFLICTING_OVERLOADS")
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
@OptIn(FreezingIsDeprecated::class)
|
||||
public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook): ReportUnhandledExceptionHook? {
|
||||
try {
|
||||
return UnhandledExceptionHookHolder.hook.swap(hook)
|
||||
|
||||
Reference in New Issue
Block a user