public Section(Course course, String sectionNumber)
throws SectionException
{
try
{
/* No checking needed as a course is defined by another class. */
this.thisCourse = course;
this.sectionNumber = DEFAULT_SECTION_NUMBER;
if( isValidSectionNumber(sectionNumber) )
this.sectionNumber = sectionNumber;
} catch( ValidationException ex )
{
throw new SectionException("Error in constructor", ex);
}
}
你好,这是我的代码,如果这个构造函数失败,我需要抛出一个SectionException,但它不允许我这样做,因为“无法访问ValidationException的catch块。这个异常永远不会从try语句主体中抛出”我该如何修复它?这是运行良好的类似代码
public Student(String studentID, String firstName, String lastName)
throws StudentException
{
/* Initialize with the provided data using the validated values. */
try
{
if( isValidStudentID(studentID) )
this.studentID = studentID;
if( isValidFirstName(firstName) )
this.firstName = firstName;
if( isValidLastName(lastName) )
this.lastName = lastName;
} catch( ValidationException ex )
{
throw new StudentException("Error in constructor", ex);
}
}
猛跑小猪
相关分类