Kotlin program of using finally block with try block

bookmark

import kotlin.ArithmeticException

fun main(args : Array<String>){
    var x = 10
    var y = 3
    try{
        println("10/3: " + x/y)

        x = 10
        y = 0 
        println("10/0: " + x/y)
    }
    finally{
        // Finally block
        println("The finally block.")
    }
}

 


Output:

10/3: 3
The finally block.
Exception in thread "main" java.lang.ArithmeticException: / by zero
 at FileKt.main (File.kt:12) 
 at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (:-2) 
 at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (:-1)