ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What are Java 7 ARM Feature and multi-catch block?

user-image
تم إضافة السؤال من قبل Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
تاريخ النشر: 2014/03/10
Maria Thomas
من قبل Maria Thomas , Tech Lead , J P Morgan Chase

Java7 ARM feature uses the concept of "try with resources". The try block now has the syntax of a method wherein the resources that will be acted upon are inserted.

Eg:

FileReader fis;

try(fis = new FileReader("c:\\\\file1.txt")){

      //code for reading from file

}catch(IOException ioex){

     //handle exception 

}

 

As can be seen above, there is no need to close the resources explicitly in finally block. Java7 takes care of this. So it has reduced the lines of code required and made it easier for the developer.

 

Multi-catch:

Java7 introduced multi catch statements in which one can use a single catch block to specify multiple exceptions that should be caught separated by pipe operator.

Eg:

try(fis = new FileReader("c:\\\\File.text"){

   //Database operations also

}catch(IOException | SQLException ex){

   //exception handling code

}

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟