Road cases 2

From reader Frank comes this delightful Java-flavored head-scratcher:

This is from the main request-handling method for a webservice. Counting all of its interesting features is left as an exercise for the reader, but the request data is never modified and the error handling in both catch blocks is the same .... The kicker is that doCalculation() has all its logic inside try {} catch (Exception ex) anyway.


Response response = new Response();
try {
    if (request.includeFooFlag()) {
        response = doCalculation(request);
    }
    if (! request.includeFooFlag()) {
        long fooCount = getCountOfFoo();
        if (fooCount == 0) {
            response = doCalculation(request);
        } else {
            try {
                response = doCalculation(request);
            } catch (Exception ex) {
                response = createErrorResponse("Error details");
                return response;
            }
        }
    }
    return response
} catch (Exception ex) {
    response = createErrorResponse("Error details");
    return response;
}
return response;

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!