WEB Button DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Kotlin - Exception Handling


Exception handling is a very important part of a programming language. This technique restricts our application from generating the wrong output at runtime.

Kotlin is pretty similar to the exceptions in Java. All the exceptions are descendants of the “Throwable” class.


fun main(args: Array) {
   try {
      val myVar:Int = 18;
      val v:String = "welookups.com";
      v.toInt();
   } catch(e:Exception) {
      e.printStackTrace();
   } finally {
      println("Exception Handeling in Kotlin");
   }
}
Hence, we will get the following output in the browser.
val myVar:Int = 18 ;
Exception Handeling in Kotlin

Note − Like Java, Kotlin also executes the finally block after executing the catch block.