1

I have my Action class below in which getTspNameIdMap throws ReqMgmtException exception (custom exception).

public String findTspNameIdMap(){

        SlsReqMgmtCommonRemote slsReqMgmtCommonRemote = null;
        tspNameIdMap = new HashMap<String, String>();

        try{
            slsReqMgmtCommonRemote = getSlsReqMgmtCommonRemote();
            tspNameIdMap = slsReqMgmtCommonRemote.getTspNameIdMap(gmaThresholdParameters.getId().getCircleId());

        }
        catch(ReqMgmtException rEx){
            addActionError(rEx.getError());
            result = "error";
            return ERROR;
        }
        catch (Exception e){    
            addActionError("Error in processing your request. Contact Administrator");
            e.printStackTrace();
            System.out.println("[ConfigureTspThresholdAction: findTspNameIdMap Function]:In catch Inside Constructor!!");
            result = "error";
            return ERROR;
        }
        return SUCCESS;
    }

I know there is exception handling in Struts2 too, however presently I am not using it. Should I use Struts2 exception handling? What would be its usage?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Siddharth Trikha
  • 2,648
  • 8
  • 57
  • 101
  • Whether or not you "should" use S2's declarative exception handling depends *entirely* on your needs. It's used to process exceptions you don't want to handle directly inside application code. – Dave Newton Jan 15 '14 at 18:08

1 Answers1

1

You should use exception handling mechanism in Struts2, that's what exception interceptor provides. Also you should handle exceptions in the action method like in your question. If it handles all exceptions good, if not the exception handler could handle it. Also in some methods which doesn't have throws Exception signature you can only catch the exception but cannot return ERROR result. So, rethrowing the exception and handling it by the interceptor is the workaround.

References:

Community
  • 1
  • 1
Roman C
  • 49,761
  • 33
  • 66
  • 176