Obscure code of the week
Not so much obscure as just.. well.. bad.. or more of the "what the hell" category.
(context: in a catch exception block, e being the Exception being caught)
object.setResponseError(new Integer(e.getErrorCode()).toString(),e.getMessage());
*blink* For just one line of simple code, it sure grabbed my attention.
Comments
Which bit is the weird bit?
Posted by: Tom | June 8, 2005 05:52 PM
Yeah, I don’t see the weirdness either.
Thinking back to other occasions, I suppose you’ll say there should be at least a temporary variable in there. Is that it, though?
Posted by: Aristotle Pagaltzis | June 8, 2005 06:43 PM
Creating an Integer object ouf of a primitive int just to get its String value....
Posted by: kasia | June 8, 2005 07:13 PM
The weird bit is one used to denote the sign of the exponent in a floating point number.
Posted by: Paul | June 8, 2005 08:35 PM
kasia: ah. I wondered that there’s got to be (at least) some class method for the job. What would the idiomatic way of doing this be, for us non-Java folk?
Posted by: Aristotle Pagaltzis | June 9, 2005 12:19 AM
Most people would use String.valueOf(int). .. Really, biggest problem with that code is how misleading it is.
Posted by: kasia | June 9, 2005 08:00 AM
let me introduce you to http://thedailywtf.com/
Posted by: Anonymous | June 9, 2005 09:30 AM
Cheese your way out:
object.setResponseError(""+e.getErrorCode(),e.getMessage());
Posted by: Mark | June 9, 2005 08:27 PM