Users Pricing

forum

Home Forums Encapsulating common exception handling logic – MindStick

Encapsulating common exception handling logic

Anonymous User 2692 12 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);
}


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md