From 52699967cdba3de8faeec272f0cf5776a3f11dcc Mon Sep 17 00:00:00 2001 From: Tamim Hossain <132823494+CodeWithTamim@users.noreply.github.com> Date: Sat, 3 Aug 2024 08:33:28 +0600 Subject: [PATCH] Simplify parseInt function (#3410) Refactored the parseInt function to use toIntOrNull() for more concise and idiomatic error handling. This change simplifies the code and avoids the need for manual exception handling --- V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt index 98120004..44769777 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt @@ -63,15 +63,10 @@ object Utils { } fun parseInt(str: String?, default: Int): Int { - str ?: return default - return try { - Integer.parseInt(str) - } catch (e: Exception) { - e.printStackTrace() - default - } + return str?.toIntOrNull() ?: default } + /** * get text from clipboard */