• Junkfoodjunkie (unregistered)

    Why in all that is holy doesn't this just return a row count for each? Either it will be null, or a positive number.

  • Naomi (unregistered)

    Does that work? Maybe it's different in C-Octothorpe, but I'd expect a try without any catch blocks to not actually catch anything .

  • (nodebb) in reply to Naomi

    Haha you are right, same thing in C#, it doesn't catch anything and the exception bubbles right out. These people are .... very inexperienced.

  • Tom (unregistered)

    This… works

    No it doesn't. A finally block is executed even if an exception occurs in the try block, but then the exception is rethrown. So, these try blocks don't actually catch anything.

  • TVJohn56 (unregistered)

    I have to admit I thought it would work as well, so I tried it. @Tom is right, you need an empty catch block at least. I would also argue that the bare minimum you should do is have a catch block with a comment in it to say why it's ok to ignore the exception.

  • darthbobo (unregistered)

    If at first you don't succeed.....

  • my name is missing (unregistered)

    Finally again, naturally.

  • Sgkgdl (unregistered)

    Even if it did work, it never resets the font style / color back to normal.

  • Carl Witthoft (google) in reply to Sgkgdl

    That's no problem -- there's an almost identical block of code with a bunch of "NOT"s inserted.

  • Could still work (unregistered)

    Don't get me wrong; it's downright without ugly w/o an alibi, but it would still work if any conditions that would throw an exception never occurred.

    I have a feeling that the evolution was: "warning: such and such throws an exception - you need a try/catch" - adds try/catch with empty catch .... "warning you can't have an empty catch" - (coyly, but incorrectly) replaces 'catch' with 'finally' .... it works, because whatever is going to trip the exceptions never happens.

    That only leaves one question - if the exception bubbles up and the coder gets warnings/errors about uncaught exceptions, then any code calling this one must have some sort of try/catch in it... so.... does it??

  • Wizofaus (unregistered)

    TRWTF is mixing low level DB access code with UI updating code. I'd love to see the unit tests.

  • BLT Collector (unregistered)

    Depending on the version of C# in play here (which I am not terribly optimistic about), the various null checking operators could have been used to avoid any exceptions:

    int changes = DataNode.DataNodeDataSet(Convert.ToInt32(Status.PendingNew))?.Tables?.FirstOrDefault()?.Rows?.Count ?? 0;
    changes += DataVersion.GetVersionTable(Convert.ToInt32(Status.PendingNew))?.Rows?.Count ?? 0;
    changes += DataOrderVersion.DataOrderVersionDataSet(Convert.ToInt32(Status.PendingNew))?.Tables?.FirstOrDefault()?.Rows?.Count ?? 0;
    

    This is, perhaps, not a very pretty way of handling the situation, but I would consider it leaps and bounds above the failed attempt at exception handling.

  • Loren Pechtel (unregistered)

    This..."works" in that it creates the correct output. However, if any stage failed it throws an exception (which I suspect is being consumed at the top of the tree--the sort of people who do this would likely handle it that way) and it doesn't reset the font if the pending count drops to zero.

  • (nodebb)

    "We don't need tests or code reviews."

  • xtal256 (unregistered)

    Gotta love how they're converting the enum values to ints. Like they didn't design the methods to accept the enum type but rather the raw int values.

  • Fnord (unregistered)

    I... may have a cow-orker who works hard at screwing up indentation that badly.

  • markm (unregistered)

    About the indentation: Does whatever text editor they are using allow having some indents with spaces and some with tabs? A file with mixed indents might look OK in the one editor, but a print utility, a different editor, or the same editor with different settings may all render the tabs differently.

    But that's a problem from the days when we used vi or a similar editor for everything because that was all we had. I can see no reason a professional programmer isn't using an editor that both corrects that problem by saving the file with all indents done the same way, and recognizes the structure of the particular program language and flags any wrong indents.

  • Paulina (unregistered)

    This kind of code makes me want to be a full time code reviewer, with the right to slap people in the face when they provide this quality of code.

  • Stuart Longland (unregistered)

    They try… but ultimately still fail.

    The indentation makes me want to open the file up in vi and type ggVG==… what did they edit this with, butterflies?

  • Craig (unregistered) in reply to Could still work

    I've never seen warnings in Visual Studio for not catching exceptions that might issue. .NET doesn't have exception specifications, so there isn't any way for the compiler to know that an exception could issue from code unless there is an explicit throw in it. The only way they could be trying to address such a warning is if it came from a linter/analysis tool.

Leave a comment on “Going Through Some Changes”

Log In or post as a guest

Replying to comment #:

« Return to Article