Daily WTF - Check Out This Gem
Related Categories: ColdFusion
A friend was searching through some legacy code when he found this absolute beauty (names changed to protect the guilty):
<cfthrow message="Invalid Number!" type="NotNumber">
</cfif>
<cftry>
<cfcatch Type="NotNumber">
</cfcatch>
</cftry>
Wow where do I begin explaining whats wrong with this code? Actually I think it speaks for itself.
What's New
Calendar
Subscribe
Enter your email address to subscribe to this blog.
Archives By Subject
AIR (9) [RSS]
Ajax (45) [RSS]
Ant (2) [RSS]
Apache Derby (4) [RSS]
Blogging (23) [RSS]
cfcExplorer (2) [RSS]
cfcFlexplorer (5) [RSS]
cfCodePress (1) [RSS]
CFCs (4) [RSS]
CFEclipse (7) [RSS]
CFeMmys (6) [RSS]
cfImageCropper (6) [RSS]
cfsnippets (15) [RSS]
cfTimeline (7) [RSS]
CFUnited (5) [RSS]
CFUnited 2007 (5) [RSS]
Code Generation (6) [RSS]
ColdFusion (309) [RSS]
Communications (1) [RSS]
CSS (5) [RSS]
Eclipse (4) [RSS]
Excel Hacks (2) [RSS]
Ext (6) [RSS]
Flash Forms (37) [RSS]
Flex (35) [RSS]
Funny Stuff (12) [RSS]
Gaming (8) [RSS]
Google (1) [RSS]
IIS (2) [RSS]
iLearn (2) [RSS]
Java (5) [RSS]
JavaScript (11) [RSS]
jQuery (7) [RSS]
Management (2) [RSS]
Misc (31) [RSS]
Mobile (1) [RSS]
Model-Glue (12) [RSS]
Networking (4) [RSS]
Off Topic (32) [RSS]
OO (5) [RSS]
Personal (35) [RSS]
picViewer (3) [RSS]
pptutils (2) [RSS]
Project Learn (10) [RSS]
Rants (9) [RSS]
Rich Applications (3) [RSS]
Sharepoint (1) [RSS]
SlideSix (49) [RSS]
SQL (37) [RSS]
Usability (5) [RSS]
Vista (4) [RSS]
Web 2.0 (2) [RSS]
Tags
Recent Comments
Adding Auto Generated Code Downloads to BlogCFC
ada5fsa said: http://www.ibiblio.org/st...
http://www.ncaonline.org/......
[More]
Chinese Birth Calendar Accuracy Test
mama to be said: ok so i will be 2 months shy of 18 when i have my baby. this calendar does not technically work for ...
[More]
Fixing 'User Profile Service Failed The Logon' on Vista
Mike said: That fix worked although all i did was remove .bak and reset state to 0.
User was able to log in to...
[More]
Chinese Birth Calendar Accuracy Test
Melissa said: Wrong for my daughter, which it predicted to be a boy... we'll see for #2. Predicts a girl (maybe, f...
[More]
Adding Auto Generated Code Downloads to BlogCFC
fweerw said: http://www.ibiblio.org/st...
http://www.cambodia.ait.a......
[More]
Blogs I Read
Brian Meloche
Brian Rinaldi
Charlie Griefer
Andy Jarrett
Joshua Cyr
Peter Bell
Brian Kotek
Jared Rypka Hauer
Joe Rinehart
Gary Gilbert
Charlie Arehart
Mark Mandel
Doug Hughes
Neil Middleton
Mark Drew
Rey Bango
Rob Gonda
Scott Pinkston
Aaron West
Aaron Lynch
Scott Stroz
Dave Shuck
Sean Corfield
Ben Forta
Dan Vega
Dan Wilson
Ben Nadel






So nice.
First of all, I have a problem with the fact that the code checks the len of the productID and throws a custom exception if it is not numeric or the length is greater then 10. Since when is an number not a number if it is greater then 10 digits?
Secondly, the whole try catch block is a giant waste. I imagine they probably wanted to put the cfif statement inside of the try/catch block - but even so the cfcatch isn't doing anything. No logging, no email, no nothing!! Even if the code were written correctly, I find it to be a bad practice to throw a custom exception and immediately catch it within a try/catch block...what's the point? I would venture to guess what they really were trying to do is simply validate the productID - if so then I'd get rid of the throw/try/catch and just validate per your business rules and create a friendly error message to show the user if the validation fails.
Check this out.
This:
http://mgt.pastebin.com/f7fb1e536
Renders this
http://www.myinternetisbroken.com/files/Shite_OutP...
What a load of crap that is!!
actually that code isn't that bad at all. pretty readable from the code itself and it's commented nicely.
the thing is, when was this code written? if it was written back in the 4.0 days, you didn't have a lot of the functionality that we do today. functions, QoQ and a lot of things didn't exists, but arrays and structures did.
I'm only stating this because before your laugh and comment on what someone wrote, you need to know the whole story.
So if this was written back in the 4.0 days, put this guy on the back. If it was written 2 weeks ago under Cf8, kick his ass.
Wow, I don't think in all my years I've ever seen such a fundamental lack of understanding the use of a query. At first I assumed that this was stateless, with no DB in the back or something ... until I saw the CFQUERY and the third set of CFSET tags. Ouch
-jfish
This was done just before I came on... V.7 so it was a couple of years ago. This guy was a piece of work....
I ranted about here.
http://www.myinternetisbroken.com/index.cfm/2007/4...
Thank good I don't do all that maintenance stuff but when I do, it makes Baby Jesus cry.
after reading your post and comment i must recant my previous position.
IT YOUR DUTY TO FIND THIS PERSON AND DESTROY HIM!!!
I only wish you can give us his name so I may warn my HR department about ever hiring him.
Surely there would have at least been something in the catch section, not much point going to the trouble to throw and catch a custom exception and then do nothing.
Not only that, but since nothing is in the try block nothing is going to be caught.
Kind regards
</cliff>
Might want to also keep an eye on dan vega's blog I think he's going to start posting some similar examples.