Minor code refinement

This commit is contained in:
Anirban Chatterjee 2020-07-16 00:38:26 +02:00
parent 793db9f42b
commit 8a76711fb5

View File

@ -28,7 +28,7 @@ class ExceptionHandling {
fun multipleCatchBlock(): Int? { fun multipleCatchBlock(): Int? {
return try { return try {
val result = 25 / 0 val result = 25 / 0
return result result
} catch (exception: NumberFormatException) { } catch (exception: NumberFormatException) {
println("NumberFormatException in the code") println("NumberFormatException in the code")
null null
@ -69,10 +69,10 @@ class ExceptionHandling {
} }
} }
fun throwKeyword() { fun throwKeyword(): Int {
val message = "Welcome to Kotlin Tutorials" val message = "Welcome to Kotlin Tutorials"
if (message.length > 10) throw IllegalArgumentException("String is invalid") if (message.length > 10) throw IllegalArgumentException("String is invalid")
else println("String is valid") else return message.length
} }
@Throws(IOException::class) @Throws(IOException::class)