No c

Checked exceptions in Java have to be handled or rethrown. This results in a lot of unnecessary code. The following example shows the try catch block how to handle the checked exceptions thrown by new FileReader("pathToFile") - throws FileNotFoundException and reader.read() - throws IOException:

    public void openSomeFileInJava(){
try {
FileReader reader = new FileReader("pathToFile");
int i=0;
while(i != -1){
i = reader.read();
//Do something with what was read
}
reader.close();
} catch (FileNotFoundException e) {
//Exception handling code
} catch (IOException e) {
//Exception handling code
}
}

Kotlin does not have any checked exceptions. It's up to the client code if they want to handle the exception. Exception handling is not forced on the client.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset