Error Handling
The Docutain SDK for Kotlin Multiplatform distinguishes between user cancellation, SDK failures and invalid arguments.
Return values
Opening a ready-to-use UI can end without a result because the user cancelled it. This is not an SDK error:
DocutainSdk.scanDocumentreturnsfalsewhen the user cancels the scan.DocutainSdk.startPhotoPaymentandDocutainSdk.startPhotoPaymentWithExternalFilesreturnnullwhen the user cancels the process.
An empty text or analysis result can mean that nothing was detected. It does not necessarily indicate an error.
Exceptions
SDK operations throw DocutainException when they fail. Its message contains the error reported by the underlying native SDK. Invalid arguments can result in standard Kotlin exceptions such as IllegalArgumentException.
Sample
import de.docutain.sdk.kmp.DocutainException
import de.docutain.sdk.kmp.DocutainSdk
val scope = rememberCoroutineScope()
scope.launch {
try {
val completed = DocutainSdk.scanDocument()
if (completed) {
val pdf = DocutainSdk.writePDF()
} else {
// user cancelled the scan process
}
} catch (exception: DocutainException) {
// the SDK operation failed
val message = exception.message
} catch (exception: IllegalArgumentException) {
// an argument was invalid
}
}
Logging
If you cannot make sense of an error, the trace file usually can. See Logging on how to obtain it and send it to us.