Click here to Skip to main content
15,843,623 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.

 
GeneralRe: !(How to best use a try catch block) Pin
supercat910-Jul-09 7:02
supercat910-Jul-09 7:02 
GeneralRe: !(How to best use a try catch block) Pin
Thomas Weller10-Jul-09 19:46
Thomas Weller10-Jul-09 19:46 
GeneralRe: !(How to best use a try catch block) Pin
supercat913-Jul-09 6:19
supercat913-Jul-09 6:19 
GeneralRe: !(How to best use a try catch block) Pin
OriginalGriff13-Jul-09 9:52
mveOriginalGriff13-Jul-09 9:52 
GeneralRe: !(How to best use a try catch block) Pin
supercat914-Jul-09 7:10
supercat914-Jul-09 7:10 
GeneralRe: !(How to best use a try catch block) Pin
BadKarma10-Jul-09 2:25
BadKarma10-Jul-09 2:25 
GeneralRe: !(How to best use a try catch block) Pin
singh.iz.king10-Jul-09 4:50
singh.iz.king10-Jul-09 4:50 
GeneralRe: !(How to best use a try catch block) Pin
Member 448708313-Jul-09 9:17
Member 448708313-Jul-09 9:17 
I don't like returning -1 for an error (particularly in this case) because -1 could be a valid result. eg. the values are all -1. There are a couple of nice solutions I can think of. One would be to use a nullable type ie. double?. The other way would be to let an exception be thrown or throw your own exceptions.

Only looking at the first four elements is probably the worst thing IMHO though. What do you think of this?

public double CrappyTotal
{
    get
    {
        double total = 0;

        foreach (var d in this.SomeItem.Details)
        {
            total += d.Value;
        }

        return total / (double)this.SomeItem.Details.Count;
    }
}


No exception handling Mad | :mad: . I would be happy without error handling. I could add a check for nulls at the start, but I don't think it's worth the time. It would probably depend how and where it was being used though.

So, are there people out there who insist that every exception must be handled?
GeneralRe: !(How to best use a try catch block) Pin
singh.iz.king13-Jul-09 16:20
singh.iz.king13-Jul-09 16:20 
GeneralRe: !(How to best use a try catch block) Pin
mateotrek18-Aug-09 20:19
mateotrek18-Aug-09 20:19 
Generalhow not to check a login [modified] Pin
icewolf_snowfire8-Jul-09 7:11
icewolf_snowfire8-Jul-09 7:11 
GeneralRe: how not to check a login Pin
0x3c08-Jul-09 7:46
0x3c08-Jul-09 7:46 
GeneralRe: how not to check a login Pin
icewolf_snowfire8-Jul-09 8:35
icewolf_snowfire8-Jul-09 8:35 
GeneralRe: how not to check a login Pin
Lutosław8-Jul-09 13:39
Lutosław8-Jul-09 13:39 
GeneralRe: how not to check a login Pin
icewolf_snowfire8-Jul-09 16:41
icewolf_snowfire8-Jul-09 16:41 
GeneralRe: how not to check a login Pin
Lutosław9-Jul-09 5:04
Lutosław9-Jul-09 5:04 
GeneralRe: how not to check a login Pin
leppie12-Jul-09 3:15
leppie12-Jul-09 3:15 
GeneralRe: how not to check a login Pin
icewolf_snowfire14-Jul-09 10:32
icewolf_snowfire14-Jul-09 10:32 
GeneralRe: how not to check a login Pin
Lutosław17-Jul-09 11:06
Lutosław17-Jul-09 11:06 
GeneralRe: how not to check a login Pin
MarkB77716-Jul-09 21:20
MarkB77716-Jul-09 21:20 
GeneralRe: how not to check a login Pin
supercat98-Jul-09 14:19
supercat98-Jul-09 14:19 
GeneralRe: how not to check a login Pin
Russell Jones13-Jul-09 6:03
Russell Jones13-Jul-09 6:03 
GeneralRe: how not to check a login Pin
supercat914-Jul-09 6:45
supercat914-Jul-09 6:45 
GeneralRe: how not to check a login Pin
Jammer13-Jul-09 7:34
Jammer13-Jul-09 7:34 
GeneralRe: how not to check a login Pin
PaPaSEK13-Jul-09 20:12
PaPaSEK13-Jul-09 20:12 

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.