diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index a52158569a9..61963e3df31 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -5152,6 +5152,15 @@ dynamicTest("interop_exceptions_throwThroughBridge") { interop = "exceptions_throwThroughBridge" } +dynamicTest("interop_kotlin_exception_hook") { + disabled = (project.testTarget == 'wasm32') // Uses exceptions + dynamic is unsupported for wasm. + source = "interop/exceptions/exceptionHook.kt" + cSource = "$projectDir/interop/exceptions/exceptionHook.cpp" + clangTool = "clang++" + expectedExitStatusChecker = { it != 0 } + outputChecker = { s -> s.contains("OK. Kotlin unhandled exception hook") } +} + interopTest("interop_exceptions_cCallback") { disabled = (project.testTarget == 'wasm32') // Uses exceptions source = "interop/exceptions/cCallback.kt" diff --git a/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.cpp b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.cpp new file mode 100644 index 00000000000..6b1ad80cabb --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.cpp @@ -0,0 +1,11 @@ +#include "testlib_api.h" + +#include + +int main(int argc, char** argv) { + try { + testlib_symbols()->kotlin.root.setHookAndThrow(); + } catch (...) { + printf("FAIL. Native catch.\n"); + } +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt new file mode 100644 index 00000000000..94adb7f23a9 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/exceptions/exceptionHook.kt @@ -0,0 +1,11 @@ +import kotlin.native.concurrent.freeze + +// KT-47828 +fun setHookAndThrow() { + val hook = { _: Throwable -> + println("OK. Kotlin unhandled exception hook") + } + hook.freeze() + setUnhandledExceptionHook(hook) + throw Exception("Error") +} \ No newline at end of file