Click here to Skip to main content
15,887,027 members

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, embarrassing 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??? Pin
Julien Villers25-Sep-12 23:45
professionalJulien Villers25-Sep-12 23:45 
GeneralRe: Parsing string to Integer with try and catch??? Pin
BobJanova26-Sep-12 0:12
BobJanova26-Sep-12 0:12 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Julien Villers26-Sep-12 1:15
professionalJulien Villers26-Sep-12 1:15 
GeneralRe: Parsing string to Integer with try and catch??? Pin
dojohansen2-Oct-12 3:51
dojohansen2-Oct-12 3:51 
GeneralRe: Parsing string to Integer with try and catch??? Pin
agolddog28-Sep-12 3:44
agolddog28-Sep-12 3:44 
AnswerRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi28-Sep-12 4:04
protectorMarco Bertschi28-Sep-12 4:04 
GeneralRe: Parsing string to Integer with try and catch??? Pin
zenwalker19859-Oct-12 17:58
zenwalker19859-Oct-12 17:58 
GeneralHappy debugging! PinPopular
Andrei Straut23-Sep-12 22:12
Andrei Straut23-Sep-12 22:12 
While debugging some problems in an automated console application I ran into this:

C#
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):

C#
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! Pin
Brisingr Aerowing24-Sep-12 2:54
professionalBrisingr Aerowing24-Sep-12 2:54 
GeneralRe: Happy debugging! PinPopular
Patrice STOESSEL24-Sep-12 19:40
Patrice STOESSEL24-Sep-12 19:40 
GeneralRe: Happy debugging! Pin
Andrei Straut24-Sep-12 20:09
Andrei Straut24-Sep-12 20:09 
GeneralRe: Happy debugging! Pin
Sentenryu25-Sep-12 0:11
Sentenryu25-Sep-12 0:11 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 0:40
Andrei Straut25-Sep-12 0:40 
GeneralRe: Happy debugging! Pin
DerekT-P25-Sep-12 1:01
professionalDerekT-P25-Sep-12 1:01 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 1:07
Andrei Straut25-Sep-12 1:07 
GeneralRe: Happy debugging! Pin
BrainiacV25-Sep-12 4:11
BrainiacV25-Sep-12 4:11 
GeneralThat was funny but.. Pin
VallarasuS24-Sep-12 22:59
VallarasuS24-Sep-12 22:59 
GeneralRe: Happy debugging! Pin
dandy7225-Sep-12 0:25
dandy7225-Sep-12 0:25 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 0:50
Andrei Straut25-Sep-12 0:50 
GeneralRe: Happy debugging! Pin
dandy7225-Sep-12 1:34
dandy7225-Sep-12 1:34 
GeneralRe: Happy debugging! PinPopular
Pete O'Hanlon25-Sep-12 2:07
mvePete O'Hanlon25-Sep-12 2:07 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 2:17
Andrei Straut25-Sep-12 2:17 
GeneralRe: Happy debugging! Pin
Pete O'Hanlon25-Sep-12 2:33
mvePete O'Hanlon25-Sep-12 2:33 
GeneralRe: Happy debugging! Pin
agolddog25-Sep-12 3:49
agolddog25-Sep-12 3:49 
GeneralRe: Happy debugging! Pin
KP Lee25-Sep-12 15:55
KP Lee25-Sep-12 15:55 

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

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