getUnhandledExceptionHook

Returns a user-defined unhandled exception hook set by setUnhandledExceptionHook or null if no user-defined hooks were set.

@ExperimentalNativeApifun getUnhandledExceptionHook(): ReportUnhandledExceptionHook?(source)
import kotlin.native.concurrent.*
import kotlin.native.runtime.*
import kotlin.native.*
import kotlin.native.*

@ExperimentalNativeApi
fun main() {
    // Define a custom unhandled exception hook that prints the exception
    val customHook: ReportUnhandledExceptionHook = { exception ->
        println("Unhandled exception captured: ${exception.message}")
    }

    // Register the hook
    setUnhandledExceptionHook(customHook)

    // Retrieve the hook we just set
    val retrievedHook = getUnhandledExceptionHook()

    // Verify that the hook is the same we registered
    println("Hook retrieved: ${retrievedHook != null}") // should print true

    // Throw an exception to see the hook in action
    throw IllegalStateException("Test exception")
}

Source