iosMain.net.iriscan.sdk.utils.ErrorUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biometric-sdk Show documentation
Show all versions of biometric-sdk Show documentation
Biometric SDK Kotlin Multiplatform library (android + ios)
package net.iriscan.sdk.utils
import kotlinx.cinterop.*
import platform.Foundation.NSError
/**
* @author Slava Gornostal
*/
internal fun throwError(block: (errorPointer: CPointer>) -> T): T =
memScoped {
val errorPointer: CPointer> = alloc>().ptr
val result: T = block(errorPointer)
val error: NSError? = errorPointer.pointed.value
if (error != null) {
throw NSErrorException(error)
} else {
return result
}
}
class NSErrorException(nsError: NSError) : Exception(nsError.toString())