首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么REC_Catch_Exception只有一个版本,而不是另一个版本?

为什么REC_Catch_Exception只有一个版本,而不是另一个版本?
EN

Stack Overflow用户
提问于 2014-07-26 16:09:49
回答 1查看 4.4K关注 0票数 3

在第一个代码(code1)中,findbugs会发现一个REC_catch_Exception警告,因为

代码语言:javascript
运行
复制
try { ... } catch (Exception e) 

不是一个好的风格。但是在第二个代码(code2)中,警告消失了。

为什么?唯一的区别是setMatrikelnummer采用的类型:IntegerString

代码语言:javascript
运行
复制
        //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");
            }
EN

回答 1

Stack Overflow用户

发布于 2014-07-29 18:16:11

当try-catch块中有多个异常时,REC_Catch_Exception触发。在第一个代码中,可能有两个异常是REC_Catch_Exception触发器,但在第二个代码中,只有一个异常是可能的,并且没有REC_Catch_Exception触发器/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24968959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档