forum

Home / DeveloperSection / Forums / Encapsulating common exception handling logic

Encapsulating common exception handling logic

Anonymous User221812-Jun-2013

I have a series of web service method calls which all follow the below format. The only difference in each method is httpRequest.methodName(). Can anybody think of a way I can encapsulate the common logic? Also note that my environment is J2ME.

public Response webserviceCall(Request request) {
 
    HTTPRequest httpRequest = new HTTPRequest(new ConnectionProperties());
 
    String errorMessage = "";
    String errorCode = "";
 
    try {
        // the only thing different
        httpRequest.methodName();
    } catch (SDKException e) {
        errorMessage = e.getMessage();
        errorCode = e.getErrorCode();
    }
 
    Error error = new Error(errorMessage,errorCode);
 
    return new Response(error);
}


Updated on 12-Jun-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By