Error codes within exception vs exceptions hierarchy
Do you think it is ok to use error codes within exception to specify error type? Please take a look on this code: public class MyException extends Exception { public static final String ERROR_CODE_INVALID_NAME = ""; public static final String ERROR_CODE_INVALID_ID = ""; ... private String errorCode; public MyException(String message, String errorCode) { super(message); this.errorCode = errorCode; } public String getErrorCode() { return errorCode; } } I know that it is better to use enum instead of Strings in this example, but I'm actually concerned about the concept of error codes. Do you