try{
A = Integer.parseInt(reader.readLine());
B = Integer.parseInt(reader.readLine());
}
catch(IOException e){
e.getStackTrace();
}
finally{
try{ /*why try catch in final block as well?*/
reader.close();
}
catch(IOException e){
e.printStackTrace();
}
}
task completed. first wrote it on IDE. But why my Ide throws compile error if i directly close the resources in finally block.
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Nouser
21 September 2020, 07:55
close throws an IOException. So you have to try catch this as well or add that exception to the method signature. Cause it's somehow uncomfortable there is try-with-resources since Java 7.
+1
Vidhya
20 September 2020, 23:33
What is the error that you are getting from the IDE
+1