I want to know what the function of try | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want to know what the function of try

Example: try (Scanner keyboard = new Scanner (System.in)) { Some of my code didnt use 'try' . Can i know why?

31st Dec 2022, 7:15 PM
Aenul
Aenul - avatar
1 Answer
+ 4
Learn about Exception handling in Java... ( try {.. } catch() {.. } blocks... Your example is having try with resources concept which is closed files automatically after that block, which you opened in try argument... You can use those, if you need them.. edit: https://www.geeksforgeeks.org/try-with-resources-feature-in-java/amp/ https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
31st Dec 2022, 8:09 PM
Jayakrishna 🇮🇳