January 2018
Intermediate to advanced
434 pages
14h 1m
English
In Kotlin, all the exceptions are unchecked, which means that we don't need to apply try–catch at all. This is quite different than Java, where if a method throws an exception, we need to surround it with try–catch.
Here's an example of an IO operation in Kotlin:
fun fileToString(file: File) : String { //readAllBytes throws IOException, but we can omit catching it fileContent = Files.readAllBytes(file) return String(fileContent) }
As you can see, we don't need to wrap things with try–catch if we don't want to. In Java, we couldn't proceed without handling this exception.
Read now
Unlock full access