[K/N] Mark UnhandledExceptionHook-related API as experimental

As a part of efforts to stabilize Native stdlib.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-03-23 14:42:25 +02:00
parent 02beaa1daa
commit 8663239369
10 changed files with 14 additions and 12 deletions
@@ -40,6 +40,7 @@ public class IncorrectDereferenceException : RuntimeException {
/**
* Typealias describing custom exception reporting hook.
*/
@ExperimentalStdlibApi
public typealias ReportUnhandledExceptionHook = Function1<Throwable, Unit>
/**
@@ -55,6 +56,7 @@ public typealias ReportUnhandledExceptionHook = Function1<Throwable, Unit>
* Set or default hook is also invoked by [processUnhandledException].
* With the legacy MM the hook must be a frozen lambda so that it could be called from any thread/worker.
*/
@ExperimentalStdlibApi
@OptIn(FreezingIsDeprecated::class)
public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook?): ReportUnhandledExceptionHook? {
try {
@@ -66,7 +68,7 @@ public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook?): Repor
@Suppress("CONFLICTING_OVERLOADS")
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@OptIn(FreezingIsDeprecated::class)
@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class)
public fun setUnhandledExceptionHook(hook: ReportUnhandledExceptionHook): ReportUnhandledExceptionHook? {
try {
return UnhandledExceptionHookHolder.hook.swap(hook)
@@ -144,7 +144,7 @@ internal fun ReportUnhandledException(throwable: Throwable) {
// Using object to make sure that `hook` is initialized when it's needed instead of
// in a normal global initialization flow. This is important if some global happens
// to throw an exception during it's initialization before this hook would've been initialized.
@OptIn(FreezingIsDeprecated::class)
@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class)
internal object UnhandledExceptionHookHolder {
internal val hook: FreezableAtomicReference<ReportUnhandledExceptionHook?> =
if (Platform.memoryModel == MemoryModel.EXPERIMENTAL) {
@@ -157,7 +157,7 @@ internal object UnhandledExceptionHookHolder {
// TODO: Can be removed only when native-mt coroutines stop using it.
@PublishedApi
@ExportForCppRuntime
@OptIn(FreezingIsDeprecated::class)
@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class)
internal fun OnUnhandledException(throwable: Throwable) {
val handler = UnhandledExceptionHookHolder.hook.value
if (handler == null) {
@@ -172,7 +172,7 @@ internal fun OnUnhandledException(throwable: Throwable) {
}
@ExportForCppRuntime("Kotlin_runUnhandledExceptionHook")
@OptIn(FreezingIsDeprecated::class)
@OptIn(FreezingIsDeprecated::class, ExperimentalStdlibApi::class)
internal fun runUnhandledExceptionHook(throwable: Throwable) {
val handler = UnhandledExceptionHookHolder.hook.value ?: throw throwable
handler(throwable)