From 2dcbe0801b9ad40cbaafa51ca2985909550f225e Mon Sep 17 00:00:00 2001 From: Prathamesh More Date: Sun, 28 Nov 2021 22:35:18 +0530 Subject: [PATCH] Using runCatching --- .../monkey/retromusic/fragments/other/UserInfoFragment.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/other/UserInfoFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/other/UserInfoFragment.kt index e3ebe33f..ea3653eb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/other/UserInfoFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/other/UserInfoFragment.kt @@ -61,7 +61,6 @@ import org.koin.androidx.viewmodel.ext.android.sharedViewModel import java.io.BufferedOutputStream import java.io.File import java.io.FileOutputStream -import java.io.IOException class UserInfoFragment : Fragment() { @@ -218,13 +217,13 @@ class UserInfoFragment : Fragment() { val appDir = requireContext().filesDir val file = File(appDir, fileName) var successful = false - try { + kotlin.runCatching { val os = BufferedOutputStream(FileOutputStream(file)) successful = ImageUtil.resizeBitmap(bitmap, 2048) .compress(Bitmap.CompressFormat.WEBP, 100, os) withContext(Dispatchers.IO) { os.close() } - } catch (e: IOException) { - e.printStackTrace() + }.onFailure { + it.printStackTrace() } if (successful) { withContext(Dispatchers.Main) {