2014-07-26 41 views
1

在第一代碼(代碼1)的FindBugs找到REC_catch_Exception警告,因爲爲什麼在一個版本中REC_Catch_Exception而不是其他版本?

try { ... } catch (Exception e) 

不是一個好作風。但在第二個代碼(code2)中,警告消失。

爲什麼?唯一的區別是類型setMatrikelnummer需要:IntegerString

 //code1: With REC_Catch_Exception 
     try { 
       // set student datas 
       currentStudent.setVorname(registration[0]); 
       currentStudent.setName(registration[1]); 
       currentStudent.setMatrikelnummer(Integer 
         .parseInt(registration[2])); 
       currentStudent.setEmail(registration[3]); 
       currentStudent.setAnrede(registration[4]); 
       currentStudent.setStudiengang(registration[5]); 

       DateFormat formatter = new SimpleDateFormat(
         "EEE MMM dd hh:mm:ss z yyyy", Locale.UK); 
       Date registrationDate = formatter.parse(registration[6]); 
       currentRegistration.setRegistrationDate(registrationDate); 

      } catch (Exception E) { 
       throw new WrongFormatException(
         "Die Textdateien befinden sich im falschen Format"); 
      } 

     //code2: Without REC_Catch_Exception 
     try { 
       // set student datas 
       currentStudent.setVorname(registration[0]); 
       currentStudent.setName(registration[1]); 
       currentStudent.setMatrikelnummer(registration[2]); 
       currentStudent.setEmail(registration[3]); 
       currentStudent.setAnrede(registration[4]); 
       currentStudent.setStudiengang(registration[5]); 

       DateFormat formatter = new SimpleDateFormat(
         "EEE MMM dd hh:mm:ss z yyyy", Locale.UK); 
       Date registrationDate = formatter.parse(registration[6]); 
       currentRegistration.setRegistrationDate(registrationDate); 

      } catch (Exception E) { 
       throw new WrongFormatException(
         "Die Textdateien befinden sich im falschen Format"); 
      } 

回答

0

當try-catch塊中有多個異常時,會觸發REC_Catch_Exception。也許在第一個代碼中,可能有兩個異常,REC_Catch_Exception會觸發,但在第二個代碼中只有一個異常可能,並且沒有REC_Catch_Exception觸發器/

相關問題