KOTLIN AND GOLANG FOR BEGINNERS: 2 BOOKS IN 1 - Learn Coding Fast! KOTLIN Programming Language And GOLANG Crash Course, A QuickStart Guide, Tutorial Book by Program Examples, In Easy Steps! by TAM SEL

KOTLIN AND GOLANG FOR BEGINNERS: 2 BOOKS IN 1 - Learn Coding Fast! KOTLIN Programming Language And GOLANG Crash Course, A QuickStart Guide, Tutorial Book by Program Examples, In Easy Steps! by TAM SEL

Author:TAM SEL [SEL, TAM]
Language: eng
Format: azw3
Published: 2020-01-02T16:00:00+00:00


Kotlin multiple catch blocks example

In the following example we have multiple catch blocks but when an exception occurs it looks for the handler for that particular exception.

The exception occurred here is Arithmetic exception, however the first two catch blocks didn’t handle the Arithmetic exception thats why the third catch block’s code executed. Third block is handling all the exceptions because it is using the Exception class which is a parent of all the exception classes.

fun main(args: Array<String>) {

try{

var num = 10/0

println(num)

}

catch(e: NumberFormatException){

println("Number format exception")

}

catch(e: ArrayIndexOutOfBoundsException){

println("Array index is out of range")

}

catch(e: Exception){

println("Some Exception occurred")

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.