Click here to Skip to main content

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrasing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
AnswerRe: Parsing string to Integer with try and catch??? PinmemberJulien Villers25-Sep-12 23:45 
GeneralRe: Parsing string to Integer with try and catch??? PinmemberBobJanova26-Sep-12 0:12 
GeneralRe: Parsing string to Integer with try and catch??? PinmemberJulien Villers26-Sep-12 1:15 
GeneralRe: Parsing string to Integer with try and catch??? Pinmemberdojohansen2-Oct-12 3:51 
GeneralRe: Parsing string to Integer with try and catch??? Pinmemberagolddog28-Sep-12 3:44 
AnswerRe: Parsing string to Integer with try and catch??? PinmemberMark Springsteen28-Sep-12 4:04 
GeneralRe: Parsing string to Integer with try and catch??? Pinmemberzenwalker19859-Oct-12 17:58 
GeneralHappy debugging! PinmemberAndrei Straut23-Sep-12 22:12 
While debugging some problems in an automated console application I ran into this:
 
try {
    //some code
} catch(Exception e) {}

I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones.
While I can sometimes understand catching Exception, why the hell didn't the guy at least log it?
 
And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):
 
class TheClass {
	
    /*Overriden the GetType class method so that it returns a different class name than it should,
    it no longer returns the name of the class it's in*/
    private string GetType() {
        return "ISyncService";
    }
    
    private int methodThatThrewError() {
        //some code
            
        try {
            //some other code
        } catch(Exception e) {
            /*We log exceptions by class name, method where it occurred 
            and exception message, plus optionally stack trace*/
            Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
 
            /*Also make sure we're always successful*/
            return successCode;
        }
            
        return successCode;
    }
}
 
Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter).
That should teach them to log stuff properly, or use the debugger.
 
Yes, I'm a devious SOB, but hey, if they don't care, why should I?
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.

GeneralRe: Happy debugging! PinmemberZac Greve24-Sep-12 2:54 
GeneralRe: Happy debugging! PinmemberPatrice STOESSEL24-Sep-12 19:40 
GeneralRe: Happy debugging! PinmemberAndrei Straut24-Sep-12 20:09 
GeneralRe: Happy debugging! PinmemberSentenryu25-Sep-12 0:11 
GeneralRe: Happy debugging! PinmemberAndrei Straut25-Sep-12 0:40 
GeneralRe: Happy debugging! PinmemberDerekTP12325-Sep-12 1:01 
GeneralRe: Happy debugging! PinmemberAndrei Straut25-Sep-12 1:07 
GeneralRe: Happy debugging! PinmemberBrainiacV25-Sep-12 4:11 
GeneralThat was funny but.. PinmemberVallarasuS24-Sep-12 22:59 
GeneralRe: Happy debugging! PinmemberDaniel Desormeaux25-Sep-12 0:25 
GeneralRe: Happy debugging! PinmemberAndrei Straut25-Sep-12 0:50 
GeneralRe: Happy debugging! PinmemberDaniel Desormeaux25-Sep-12 1:34 
GeneralRe: Happy debugging! PinprotectorPete O'Hanlon25-Sep-12 2:07 
GeneralRe: Happy debugging! PinmemberAndrei Straut25-Sep-12 2:17 
GeneralRe: Happy debugging! PinprotectorPete O'Hanlon25-Sep-12 2:33 
GeneralRe: Happy debugging! Pinmemberagolddog25-Sep-12 3:49 
GeneralRe: Happy debugging! PinmemberKP Lee25-Sep-12 15:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 12 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid