Click here to Skip to main content
12,454,104 members (59,239 online)

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.

 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi25-Sep-12 3:36
memberMarco Bertschi25-Sep-12 3:36 
GeneralRe: Parsing string to Integer with try and catch??? Pin
KP Lee28-Sep-12 22:17
memberKP Lee28-Sep-12 22:17 
AnswerRe: Parsing string to Integer with try and catch??? Pin
Mark Springsteen30-Sep-12 21:01
memberMark Springsteen30-Sep-12 21:01 
GeneralRe: Parsing string to Integer with try and catch??? Pin
dojohansen2-Oct-12 3:48
memberdojohansen2-Oct-12 3:48 
GeneralRe: Parsing string to Integer with try and catch??? Pin
BobJanova25-Sep-12 3:53
memberBobJanova25-Sep-12 3:53 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi25-Sep-12 4:05
memberMarco Bertschi25-Sep-12 4:05 
AnswerRe: Parsing string to Integer with try and catch??? Pin
Julien Villers25-Sep-12 23:45
memberJulien Villers25-Sep-12 23:45 
GeneralRe: Parsing string to Integer with try and catch??? Pin
BobJanova26-Sep-12 0:12
memberBobJanova26-Sep-12 0:12 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Julien Villers26-Sep-12 1:15
memberJulien Villers26-Sep-12 1:15 
GeneralRe: Parsing string to Integer with try and catch??? Pin
dojohansen2-Oct-12 3:51
memberdojohansen2-Oct-12 3:51 
GeneralRe: Parsing string to Integer with try and catch??? Pin
agolddog28-Sep-12 3:44
memberagolddog28-Sep-12 3:44 
AnswerRe: Parsing string to Integer with try and catch??? Pin
Mark Springsteen28-Sep-12 4:04
memberMark Springsteen28-Sep-12 4:04 
GeneralRe: Parsing string to Integer with try and catch??? Pin
zenwalker19859-Oct-12 17:58
memberzenwalker19859-Oct-12 17:58 
GeneralHappy debugging! Pin
Andrei Straut23-Sep-12 22:12
memberAndrei 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! Pin
Zac Greve24-Sep-12 2:54
memberZac Greve24-Sep-12 2:54 
GeneralRe: Happy debugging! Pin
Patrice STOESSEL24-Sep-12 19:40
memberPatrice STOESSEL24-Sep-12 19:40 
GeneralRe: Happy debugging! Pin
Andrei Straut24-Sep-12 20:09
memberAndrei Straut24-Sep-12 20:09 
GeneralRe: Happy debugging! Pin
Sentenryu25-Sep-12 0:11
memberSentenryu25-Sep-12 0:11 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 0:40
memberAndrei Straut25-Sep-12 0:40 
GeneralRe: Happy debugging! Pin
DerekTP12325-Sep-12 1:01
memberDerekTP12325-Sep-12 1:01 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 1:07
memberAndrei Straut25-Sep-12 1:07 
GeneralRe: Happy debugging! Pin
BrainiacV25-Sep-12 4:11
memberBrainiacV25-Sep-12 4:11 
GeneralThat was funny but.. Pin
VallarasuS24-Sep-12 22:59
memberVallarasuS24-Sep-12 22:59 
GeneralRe: Happy debugging! Pin
Daniel Desormeaux25-Sep-12 0:25
memberDaniel Desormeaux25-Sep-12 0:25 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 0:50
memberAndrei Straut25-Sep-12 0:50 
GeneralRe: Happy debugging! Pin
Daniel Desormeaux25-Sep-12 1:34
memberDaniel Desormeaux25-Sep-12 1:34 
GeneralRe: Happy debugging! Pin
Pete O'Hanlon25-Sep-12 2:07
protectorPete O'Hanlon25-Sep-12 2:07 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 2:17
memberAndrei Straut25-Sep-12 2:17 
GeneralRe: Happy debugging! Pin
Pete O'Hanlon25-Sep-12 2:33
protectorPete O'Hanlon25-Sep-12 2:33 
GeneralRe: Happy debugging! Pin
agolddog25-Sep-12 3:49
memberagolddog25-Sep-12 3:49 
GeneralRe: Happy debugging! Pin
KP Lee25-Sep-12 15:55
memberKP Lee25-Sep-12 15:55 
GeneralRe: Happy debugging! Pin
SeattleC++25-Sep-12 5:12
memberSeattleC++25-Sep-12 5:12 
GeneralRe: Happy debugging! Pin
Joe_Dert20-Oct-12 21:50
memberJoe_Dert20-Oct-12 21:50 
GeneralRe: Happy debugging! Pin
SeattleC++21-Oct-12 9:14
memberSeattleC++21-Oct-12 9:14 
GeneralRe: Happy debugging! Pin
Joe_Dert21-Oct-12 20:33
memberJoe_Dert21-Oct-12 20:33 
GeneralRe: Happy debugging! Pin
BobJanova25-Sep-12 5:16
memberBobJanova25-Sep-12 5:16 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 6:45
memberAndrei Straut25-Sep-12 6:45 
GeneralRe: Happy debugging! Pin
RafagaX25-Sep-12 5:34
memberRafagaX25-Sep-12 5:34 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 6:46
memberAndrei Straut25-Sep-12 6:46 
GeneralRe: Happy debugging! Pin
Behzad Sedighzadeh25-Sep-12 5:59
memberBehzad Sedighzadeh25-Sep-12 5:59 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 6:50
memberAndrei Straut25-Sep-12 6:50 
GeneralRe: Happy debugging! Pin
jschell25-Sep-12 7:51
memberjschell25-Sep-12 7:51 
Generalwell... Pin
shiprat25-Sep-12 9:15
membershiprat25-Sep-12 9:15 
GeneralRe: well... Pin
Pete O'Hanlon25-Sep-12 9:53
protectorPete O'Hanlon25-Sep-12 9:53 
GeneralRe: well... Pin
shiprat29-Oct-12 12:56
membershiprat29-Oct-12 12:56 
GeneralRe: Happy debugging! Pin
Member 822285825-Sep-12 10:03
memberMember 822285825-Sep-12 10:03 
GeneralRe: Happy debugging! Pin
Richard Deeming26-Sep-12 3:56
memberRichard Deeming26-Sep-12 3:56 
GeneralRe: Happy debugging! Pin
amity200126-Sep-12 4:28
memberamity200126-Sep-12 4:28 
GeneralRe: Happy debugging! Pin
Le Gauchiste26-Sep-12 6:43
memberLe Gauchiste26-Sep-12 6:43 
GeneralRe: Happy debugging! Pin
greldak27-Sep-12 21:51
membergreldak27-Sep-12 21:51 

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.


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 30 Aug 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid