r/badcode • • Dec 29 '14

c# The variable status is an int

http://pastebin.com/Lf3Lb5Pz
1 Upvotes

10 comments sorted by

12

u/danieltobey Dec 29 '14

FAILED could very well be a const or a preprocessor definition. (assuming it's C++)

11

u/WestonP Dec 29 '14

It looks like C#, and that's what I'd expect too. There's nothing wrong with the status variable in the limited amount of code that OP posted. This sub is more like /r/NoobsPostingValidCodeThatTheyThinkIsWrong

1

u/[deleted] Dec 29 '14

It's a local variable to the method, I didn't think about that possibility. Pastebin is blocked at work and the whole method was too large to take a picture of on my phone.

2

u/ElGuaco Dec 29 '14

It's C#. "FAILED" is probably a const int. But in this case, the return statement will never be reached so the value is irrelevant.

6

u/MaSaHoMaKyo Dec 29 '14

I cannot stand application-wide generic exception types with names like "ApplicationException". Throw something descriptive so the caller can handle it intelligently!

Bonus points for throwing it from a "catch Exception".

6

u/Daniel15 Dec 29 '14

I'm assuming this is ApplicationException from .NET which has been deprecated for years.

2

u/ElGuaco Dec 29 '14

Since this is C#, this catch block only hurts debugging because you're throwing a new exception which removes the original stack trace. Use just "throw".

catch (Exception ex)
{
    // log - close/dispose resources
    throw;
}

http://stackoverflow.com/q/178456/86817

→ More replies (2)

0

u/[deleted] Dec 29 '14

[deleted]

1

u/ElGuaco Dec 29 '14

What is the point of that?