[Android] SlaveRepository: catch SQLiteException

Geoffrey Métais git at videolan.org
Thu Feb 14 11:15:41 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 14 11:01:01 2019 +0100| [bd49a62ecf37071bbea2091fac4fa9c21a9e9d8d] | committer: Geoffrey Métais

SlaveRepository: catch SQLiteException

> https://code.videolan.org/videolan/vlc-android/commit/bd49a62ecf37071bbea2091fac4fa9c21a9e9d8d
---

 .../src/org/videolan/vlc/repository/SlaveRepository.kt       | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/repository/SlaveRepository.kt b/vlc-android/src/org/videolan/vlc/repository/SlaveRepository.kt
index aadeb43e5..ff75c2a38 100644
--- a/vlc-android/src/org/videolan/vlc/repository/SlaveRepository.kt
+++ b/vlc-android/src/org/videolan/vlc/repository/SlaveRepository.kt
@@ -21,8 +21,12 @@
 package org.videolan.vlc.repository
 
 import android.content.Context
+import android.database.sqlite.SQLiteException
 import android.net.Uri
-import kotlinx.coroutines.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
 import org.videolan.libvlc.Media
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.tools.IOScopedObject
@@ -48,7 +52,11 @@ class SlaveRepository(private val slaveDao:SlaveDao) : IOScopedObject() {
 
     suspend fun getSlaves(mrl: String): List<Media.Slave> {
         return withContext(Dispatchers.IO) {
-            val slaves = slaveDao.get(mrl)
+            val slaves = try {
+                slaveDao.get(mrl)
+            } catch (e: SQLiteException) {
+                emptyList<Slave>()
+            }
             val mediaSlaves = slaves.map {
                 var uri = it.uri
                 if (uri.isNotEmpty())



More information about the Android mailing list