Workaround some potential exceptions

This commit is contained in:
Naveen 2022-11-03 23:49:55 +05:30
parent 09956f809d
commit b6012f6e2b
2 changed files with 25 additions and 10 deletions

View file

@ -8,7 +8,12 @@ import ezvcard.VCard
fun parseVCardFromUri(context: Context, uri: Uri, callback: (vCards: List<VCard>) -> Unit) {
ensureBackgroundThread {
val inputStream = context.contentResolver.openInputStream(uri)
val inputStream = try {
context.contentResolver.openInputStream(uri)
} catch (e: Exception) {
callback(emptyList())
return@ensureBackgroundThread
}
val vCards = Ezvcard.parse(inputStream).all()
callback(vCards)
}