SooYoung
02/16/2022, 5:27 PMoverride suspend fun write(data: ByteArray) = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
context.openFileOutput(fileName, Context.MODE_PRIVATE).use {
it.write(data)
}
}
Casey Brooks
02/16/2022, 5:32 PMopenFileOutput
throws an IOException
, and that warning expects it to be wrapped in a try/catch block, tooSooYoung
02/16/2022, 5:33 PMSooYoung
02/16/2022, 5:35 PMrunCatching {
}
I don’t know the difference.SooYoung
02/16/2022, 5:36 PMtry {
context.openFileOutput(fileName, Context.MODE_PRIVATE).use {
it.write(data)
}
} catch (e: IOException) {
}
vs
runCatching {
context.openFileOutput(fileName, Context.MODE_PRIVATE).use {
it.write(data)
}
}
gildor
02/17/2022, 2:13 AMgildor
02/17/2022, 2:14 AMgildor
02/17/2022, 2:15 AMgildor
02/17/2022, 2:16 AMIt’s gone when I wrapped the code block withIt’s one more sign that this check is not very accurate, runCatching just hides this call in lambda, so check doesn’t detect that runCatching is just an inline function with try/catch
SooYoung
02/17/2022, 2:20 AMgildor
02/17/2022, 2:26 AMgildor
02/17/2022, 2:28 AMand that warning expects it to be wrapped in a try/catch block, tooI don’t think it’s correct, this warning is not expecting try/catch or any other error handling