• Ben (unregistered)

    Hey, let's be honest. The code does one thing right:

    It uses "throw" instead of "throw ex". The latter is what I'm fighting here, because most of the time it does NOT what the programmer intended.

    So.. 1 point for understanding rethrowing, -10 for useless crap?

  • Anonymous (unregistered) in reply to Ben
    Ben:
    Hey, let's be honest. The code does one thing right:

    It uses "throw" instead of "throw ex". The latter is what I'm fighting here, because most of the time it does NOT what the programmer intended.

    So.. 1 point for understanding rethrowing, -10 for useless crap?

    I don't think the original coder even deserves that 1 point for understanding rethrowing. I don't think he understood anything of the sort, he just generated some boiler-plate code and the IDE populated each "catch" clause. The fact he never went back to flesh out the boiler plate code with something meaningful shows he doesn't have a clue.

  • (cs) in reply to eric76
    eric76:
    It's also possible that the author may have had the intention of going back later and adding some code to handle exceptions later and so he left "stubs" for that purpose.

    I concur. I figured maybe they were having some database connection issues and left it in so they could easily debug it later (or, as you suggest, as a reminder to get back to it later).

    It's not good, but it's not in the evil category

  • Mike (unregistered) in reply to Ethan Qix

    My boss does that all the time. Drives me nuts.

  • Mike (unregistered) in reply to Mike
    Mike:
    My boss does that all the time. Drives me nuts.

    D'OH - I meant to quote the part about catching "Exception" and just ignoring it. Sorry guys. heads for coffee machine

  • (cs) in reply to Spivonious
    Spivonious:
    It's better than "On Error Resume Next".

    Oh we had an error? It's okay, keep going.

    Better in what way? I can see that it's slower, but I'm not sure that's a significant improvement ... Ignoring your errors isn't a good programming practice. Pretending not to ignore them isn't a step up--at best, it's an acknowledgment that you know you're doing it wrong, but you don't care.

  • Ben (unregistered) in reply to Anonymous
    Anonymous:
    Ben:
    Hey, let's be honest. The code does one thing right:

    It uses "throw" instead of "throw ex". The latter is what I'm fighting here, because most of the time it does NOT what the programmer intended.

    So.. 1 point for understanding rethrowing, -10 for useless crap?

    I don't think the original coder even deserves that 1 point for understanding rethrowing. I don't think he understood anything of the sort, he just generated some boiler-plate code and the IDE populated each "catch" clause. The fact he never went back to flesh out the boiler plate code with something meaningful shows he doesn't have a clue.

    Sorry, but I don't buy that. An IDE that has "throw" as template code for a catch block is crap^Wmisconfigured. The default for VS would be (afaik) a comment or nothing at all, not a "throw".

  • Darth Yoda (unregistered)

    No. Try not. Do... or do not. There is no try.

  • Shinobu (unregistered) in reply to silent d
    silent d:
    The stronger you try to grasp the DAO, the more it slips through your fingers.
    That brought a smile to my face. Thank you.
  • Crimson (unregistered) in reply to LightStyx
    LightStyx:
    IndexOutOfRangeException! I choose you! *throws exception* Use InnerException now!

    It's Supper Effective! Maintenance Programmer Faints!

  • Design Pattern (unregistered) in reply to fjf
    fjf:
    Try Comment.Post () Catch ex As FristException Throw Catch ex As WoodenTableException Throw Catch ex As XMLException Throw Catch ex As FileNotFoundException Throw Catch ex As EmbeddedSystemException Throw // TODO: add more exceptions End Try

    Catch ex As BrillantPaulaBeanException Throw Catch ex As GeneralException Throw Catch ex As CAPTCHAException Throw Catch ex As BobXException XBobThrow Catch ex As MandatoryFunDay Paint

  • Design Pattern (unregistered) in reply to Oneway
    Oneway:
    I would vote for introducing a new language function that would reexecute code that raised the error, but in a more 'forceful' way. Something like:

    try { //Mess up code here } catch (Exception $e) { // handle exception } try_harder { // execute again. }

    Smalltalk and Lisp already had the option to resume execution at the point an exception was thrown: http://www.cincomsmalltalk.com/blog/blogView?entry=3321788777&showComments=true

  • Anonymous (unregistered) in reply to Ben
    Ben:
    Anonymous:
    Ben:
    Hey, let's be honest. The code does one thing right:

    It uses "throw" instead of "throw ex". The latter is what I'm fighting here, because most of the time it does NOT what the programmer intended.

    So.. 1 point for understanding rethrowing, -10 for useless crap?

    I don't think the original coder even deserves that 1 point for understanding rethrowing. I don't think he understood anything of the sort, he just generated some boiler-plate code and the IDE populated each "catch" clause. The fact he never went back to flesh out the boiler plate code with something meaningful shows he doesn't have a clue.
    Sorry, but I don't buy that. An IDE that has "throw" as template code for a catch block is crap^Wmisconfigured. The default for VS would be (afaik) a comment or nothing at all, not a "throw".
    What on Earth makes you think it was generated by VS? Or even an IDE at all (could have been a third-party generator, a custom generator that was written using the System.CodeDom.Compiler classes, there are LOTS of possibilities). As others have already pointed out, this is almost certainly generated code because it includes a catch clause for every exception that can be thrown by the CreateInstance method and it even lists them all in alphabetical order. Notice also how the catch for the TargetInvocationException is fully qualified as Reflection.TargetInvocationException. This is exactly what a code generator would spit out if the System.Reflection namespace was not in scope due to a missing "using" clause. I have no doubt this is generated code, the WTF is the fact that the original coder didn't bother to flesh it out after he generated it.

  • (cs) in reply to Anonymous
    Anonymous:
    Ben:
    Anonymous:
    Ben:
    Hey, let's be honest. The code does one thing right:

    It uses "throw" instead of "throw ex". The latter is what I'm fighting here, because most of the time it does NOT what the programmer intended.

    So.. 1 point for understanding rethrowing, -10 for useless crap?

    I don't think the original coder even deserves that 1 point for understanding rethrowing. I don't think he understood anything of the sort, he just generated some boiler-plate code and the IDE populated each "catch" clause. The fact he never went back to flesh out the boiler plate code with something meaningful shows he doesn't have a clue.
    Sorry, but I don't buy that. An IDE that has "throw" as template code for a catch block is crap^Wmisconfigured. The default for VS would be (afaik) a comment or nothing at all, not a "throw".
    What on Earth makes you think it was generated by VS? Or even an IDE at all (could have been a third-party generator, a custom generator that was written using the System.CodeDom.Compiler classes, there are LOTS of possibilities). As others have already pointed out, this is almost certainly generated code because it includes a catch clause for every exception that can be thrown by the CreateInstance method and it even lists them all in alphabetical order. Notice also how the catch for the TargetInvocationException is fully qualified as Reflection.TargetInvocationException. This is exactly what a code generator would spit out if the System.Reflection namespace was not in scope due to a missing "using" clause. I have no doubt this is generated code, the WTF is the fact that the original coder didn't bother to flesh it out after he generated it.

    Not only are those exceptions not in alphabetical order, but they don't cover all possible exceptions that can be thrown by the two method calls in that line of code.

    http://msdn.microsoft.com/en-us/library/d133hta4.aspx

    http://msdn.microsoft.com/en-us/library/a87che9d.aspx

  • Anonymous (unregistered) in reply to frits
    frits:
    Anonymous:
    Ben:
    Anonymous:
    Ben:
    Hey, let's be honest. The code does one thing right:

    It uses "throw" instead of "throw ex". The latter is what I'm fighting here, because most of the time it does NOT what the programmer intended.

    So.. 1 point for understanding rethrowing, -10 for useless crap?

    I don't think the original coder even deserves that 1 point for understanding rethrowing. I don't think he understood anything of the sort, he just generated some boiler-plate code and the IDE populated each "catch" clause. The fact he never went back to flesh out the boiler plate code with something meaningful shows he doesn't have a clue.
    Sorry, but I don't buy that. An IDE that has "throw" as template code for a catch block is crap^Wmisconfigured. The default for VS would be (afaik) a comment or nothing at all, not a "throw".
    What on Earth makes you think it was generated by VS? Or even an IDE at all (could have been a third-party generator, a custom generator that was written using the System.CodeDom.Compiler classes, there are LOTS of possibilities). As others have already pointed out, this is almost certainly generated code because it includes a catch clause for every exception that can be thrown by the CreateInstance method and it even lists them all in alphabetical order. Notice also how the catch for the TargetInvocationException is fully qualified as Reflection.TargetInvocationException. This is exactly what a code generator would spit out if the System.Reflection namespace was not in scope due to a missing "using" clause. I have no doubt this is generated code, the WTF is the fact that the original coder didn't bother to flesh it out after he generated it.

    Not only are those exceptions not in alphabetical order, but they don't cover all possible exceptions that can be thrown by the two method calls in that line of code.

    http://msdn.microsoft.com/en-us/library/d133hta4.aspx

    http://msdn.microsoft.com/en-us/library/a87che9d.aspx

    To be honest I didn't even read the article, I thought it was the norm around here to just spout off about crap I know nothing about.
  • (cs) in reply to Spivonious
    Spivonious:
    It's better than "On Error Resume Next".

    Oh we had an error? It's okay, keep going.

    I think it's funny that this feature is being picked on. VB is often criticized by fans of languages with a more succinct syntax, many of which have their roots in C. "On Error Resume Next" exists so that VB can use a more C-like error handling paradigm where control always goes to the next statement and it's the next statement's responsibility to verify that the previous statement succeeded.

    So, VB is bad because it is not like C, but it is also bad for having a feature that makes it more like C.

  • (cs) in reply to Anonymous
    Anonymous:
    To be honest I didn't even read the article, I thought it was the norm around here to just spout off about crap I know nothing about.

    I applaud you for your honesty and ability to fit in.

  • Scott Schottler (unregistered) in reply to frits

    I finally got a WTF! And no - it's not some boiler plate code that can't be modified without upsetting the original code generator. I've seen the monkeys with my own eyes type up this sort of code and implement this bastardized factory/dao pattern over and over. When I first started, I suggested they use a simple object-relational mapper I had previously developed to automate some of the tedium, and everyone got really excited. Unfortunately, it didn't work because it depended on SQL Server metadata to detect foreign keys, and the DBAs had inexplicably outlawed foreign keys on ALL TABLES.

    Here's another snippet from the same file:

    Imports System.Exception Imports System.ApplicationException

    I could zip up the entire application as one big WTF. They secured the administration portion by hiding the admin links on the main page, but there's nothing stopping someone from just typing the admin url directly.

  • (cs) in reply to John
    John:
    The WTF is it doesnt handle FileNotFoundException. And it should also get the list of exceptions from an XML file. obviously.

    The old "joke" about XML really isn't funny any more.

    FileNotFound is wearing thin.

  • Jen (unregistered) in reply to bertram
    bertram:
    John:
    The WTF is it doesnt handle FileNotFoundException. And it should also get the list of exceptions from an XML file. obviously.

    The old "joke" about XML really isn't funny any more.

    FileNotFound is wearing thin.

    But on an embedded system with no room for a filesystem, FileNotFound is the only joke we have left!

    (This marks my first and hopefully last TDWTF meme joke).

  • user unknown (unregistered)

    Professionals handle the exception in a smooth way:

    		try
    		{
    			no = Integer.parseInt (param);
    		}
    		catch (NumberFormatException nfe)
    		{
    			no = nfe.getMessage().length ();
    		}
    
  • mevryck (unregistered)

    Guess try { //blah blah } catch (Throwable t) { //meh meh } could've helped but I'm not sure if V$ supports 'Throwable' :D

  • (cs) in reply to Scott Schottler
    Scott Schottler:
    Unfortunately, it didn't work because it depended on SQL Server metadata to detect foreign keys, and the DBAs had inexplicably outlawed foreign keys on ALL TABLES.
    I take it that the job title 'DBA' at this company stands for 'Database Assassin'.
    Scott Schottler:
    They secured the administration portion by hiding the admin links on the main page, but there's nothing stopping someone from just typing the admin url directly.
    Ah, but how could they possibly find out the admin URL? Other than by major-league hacker maneuvers, like ... um ... viewing the page HTML source ... OK, never mind.
  • Sigh (unregistered) in reply to John

    Don't u people ever get tired of these old jokes?

  • DD5 (unregistered)

    The Diaper anti-pattern is actually encouraged by .NET, while Java forces you to handle your Exceptions, .NET doesn't. So when you end up having shit crawl up to the main program, you can't really know which Exceptions are being thrown, as the methods don't have a throws clause. This makes it so that the only way to guarantee catching the Exception is ... well... catching Exception.

    At least with Java, you know what kind of Exceptions you're going to get.

  • Eric de Redelijkheid (unregistered)

    A slight misinterpretation of static code analysis warning CA1031: Thou shalt not catch general exception types?

  • JC (unregistered) in reply to LightStyx
    LightStyx:
    IndexOutOfRangeException! I choose you! *throws exception* Use InnerException now!

    Got to catchem all Exceptionemon! hahaha This is ridiculous hahaha This is the most useless code statements - dont they realize that if there is an exception it will be thrown anyway?? hahahaha

  • (cs)
    Function BBQ()
        Try
            StartGrill()
        Catch Fire
            Throw Blanket
        End Try
    ...
    End Function
    

Leave a comment on “Try... Catch-em-all”

Log In or post as a guest

Replying to comment #:

« Return to Article