[K/N] Internalize functions for throwing specific exception from C++ code

As a part of efforts to stabilize Native stdlib.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-04-06 20:45:53 +03:00
parent 95f1d0b6ae
commit 72f87ba55f
@@ -11,7 +11,8 @@ import kotlin.native.concurrent.FreezableAtomicReference
import kotlin.native.concurrent.freeze
@ExportForCppRuntime
fun ThrowNullPointerException(): Nothing {
@PublishedApi
internal fun ThrowNullPointerException(): Nothing {
throw NullPointerException()
}
@@ -26,23 +27,27 @@ internal fun ThrowArrayIndexOutOfBoundsException(): Nothing {
}
@ExportForCppRuntime
fun ThrowClassCastException(instance: Any, typeInfo: NativePtr): Nothing {
@PublishedApi
internal fun ThrowClassCastException(instance: Any, typeInfo: NativePtr): Nothing {
val clazz = KClassImpl<Any>(typeInfo)
throw ClassCastException("${instance::class} cannot be cast to $clazz")
}
@ExportForCppRuntime
fun ThrowTypeCastException(instance: Any, typeName: String): Nothing {
@PublishedApi
internal fun ThrowTypeCastException(instance: Any, typeName: String): Nothing {
throw TypeCastException("${instance::class} cannot be cast to class $typeName")
}
@ExportForCppRuntime
fun ThrowKotlinNothingValueException(): Nothing {
@PublishedApi
internal fun ThrowKotlinNothingValueException(): Nothing {
throw KotlinNothingValueException()
}
@ExportForCppRuntime
fun ThrowInvalidReceiverTypeException(klass: KClass<*>): Nothing {
@PublishedApi
internal fun ThrowInvalidReceiverTypeException(klass: KClass<*>): Nothing {
throw RuntimeException("Unexpected receiver type: " + (klass.qualifiedName ?: "noname"))
}
@@ -61,11 +66,13 @@ internal fun ThrowOutOfMemoryError() : Nothing {
throw OutOfMemoryError()
}
fun ThrowNoWhenBranchMatchedException(): Nothing {
@PublishedApi
internal fun ThrowNoWhenBranchMatchedException(): Nothing {
throw NoWhenBranchMatchedException()
}
fun ThrowUninitializedPropertyAccessException(propertyName: String): Nothing {
@PublishedApi
internal fun ThrowUninitializedPropertyAccessException(propertyName: String): Nothing {
throw UninitializedPropertyAccessException("lateinit property $propertyName has not been initialized")
}