Article 1W91H CodeSOD: Every Possible Case

CodeSOD: Every Possible Case

by
Ellis Morning
from The Daily WTF on (#1W91H)

Road_cases_2.jpg

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;
puppetlabs50.png[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today! TheDailyWtf?d=yIl2AUoC8zAcgjE-kPGazo
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments