We have a Class A exception with several error codes defined as public static final, and in many files (over 100) we refer to our source code. We want all these DTCs in class B to be processed.
We have currently implemented a class method getFaultCodes()in class A to create a list of fault codes and return them. The problem with this approach is that whenever an error code is entered, it must also be added to the method getFaultCode. This is a mistake because the user may forget to add new code to the method.
Moving these trouble codes under enumrequires changes to many files throughout the source code, so we don’t want to do this.
class ExceptionA {
public static final String faultCode1 = "CODE1";
public static final String faultCode2 = "CODE1";
public static final String faultCode3 = "CODE1";
List<String> getFaultCodes(){
list.add(faultCode1);
......
return list;
}
}
, , , . , .