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
This commit is contained in:
Tamim Hossain
2024-08-03 08:33:28 +06:00
committed by GitHub
parent 146d20ce86
commit 52699967cd

View File

@@ -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
*/