I have an OpenHandler which performs some validation. I want to open the session only if the validation passes, otherwise I want to close the session immediately. I have the following lines of code in my OpenHandler:
// Open session only if no errors
if (valid()) {
SessionModel sessionModel = (SessionModel) model;
sessionModel.setOpen();
} else {
throw new ToolException("Cannot open session; validation failed.");
}
However this still opens the session if the validation fails. What do I need to change?