I have a try/catch
in my code. Inside the try I have different validations, each one throws an exception type that in turn extends the "general exception" parent class:
GENERAL EXCEPTION
public abstract class GeneralException extends Exception {
public GeneralException (String errorMessage) {
super(errorMessage);
}
public abstract int getError();
}
EXAMPLE OF DAUGHTER EXCEPTION
public static final String ERROR = "String exception";
public IncorrectStrException(String errorMessage) {
super(ERROR);
}
@Override
public int getError() {
return ERROR;
}
This is the code where I want to do the printStackTrace
of all the exceptions that are thrown and save them in a list. However, it only saves the first exception. Does this happen because the execution stops when it is launched? I am new with exceptions, I have been searching and I have not found anything.
try {
if (validateNum() && validateStr() && validateDate() && validateName()) {
generateDoc();
}
} catch (GeneralException e) {
e.printStackTrace();
exceptionList.add(e);
}
EXAMPLE OF VALIDATEX ()
public boolean validateInt(XSSFCell cell) throws IncorrectIntException {
boolean validation = false;
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
validation = true;
}
return validation;
}