Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. But it works ...

But it works ...

Scheduled Pinned Locked Moved The Weird and The Wonderful
databaseannouncement
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    There are increasing numbers of questions being posted with code similar to:

    try {
        callAPIMethodThatReturnsStatus(some parameters)
    }
    catch (SomeException e) {
        take exceptional action
    }
    
    display ('The method completed successfully');
    

    And yet they never check the returned status of the method call. Someone is teaching students/newbies that if it does not throw an exception then it must have worked. This seems most common with database update commands. Get your money out of the bank quickly.

    P Kornfeld Eliyahu PeterK B 3 Replies Last reply
    0
    • L Lost User

      There are increasing numbers of questions being posted with code similar to:

      try {
          callAPIMethodThatReturnsStatus(some parameters)
      }
      catch (SomeException e) {
          take exceptional action
      }
      
      display ('The method completed successfully');
      

      And yet they never check the returned status of the method call. Someone is teaching students/newbies that if it does not throw an exception then it must have worked. This seems most common with database update commands. Get your money out of the bank quickly.

      P Offline
      P Offline
      Power Puff Boy
      wrote on last edited by
      #2

      Maybe the return type of callAPIMethodThatReturnsStatus was poop and the programmer didn't want to deal with that s#!t.

      Kitty at my foot and I waAAAant to touch it...

      1 Reply Last reply
      0
      • L Lost User

        There are increasing numbers of questions being posted with code similar to:

        try {
            callAPIMethodThatReturnsStatus(some parameters)
        }
        catch (SomeException e) {
            take exceptional action
        }
        
        display ('The method completed successfully');
        

        And yet they never check the returned status of the method call. Someone is teaching students/newbies that if it does not throw an exception then it must have worked. This seems most common with database update commands. Get your money out of the bank quickly.

        Kornfeld Eliyahu PeterK Offline
        Kornfeld Eliyahu PeterK Offline
        Kornfeld Eliyahu Peter
        wrote on last edited by
        #3

        Not to mention the headless use of try-catch - I wonder who will pay the bill at the end...

        Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

        "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

        L 1 Reply Last reply
        0
        • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

          Not to mention the headless use of try-catch - I wonder who will pay the bill at the end...

          Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Kornfeld Eliyahu Peter wrote:

          I wonder who will pay the bill at the end

          Oh, that will be us poor customers.

          1 Reply Last reply
          0
          • L Lost User

            There are increasing numbers of questions being posted with code similar to:

            try {
                callAPIMethodThatReturnsStatus(some parameters)
            }
            catch (SomeException e) {
                take exceptional action
            }
            
            display ('The method completed successfully');
            

            And yet they never check the returned status of the method call. Someone is teaching students/newbies that if it does not throw an exception then it must have worked. This seems most common with database update commands. Get your money out of the bank quickly.

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            Well, I saw such type of code also at the then biggest vendor of hospital information systems... But they were one step better than your example: they stored the return value of the call to third party in a variable, which they never checked. That's an enormous step forward already, isn't it?

            D 1 Reply Last reply
            0
            • B Bernhard Hiller

              Well, I saw such type of code also at the then biggest vendor of hospital information systems... But they were one step better than your example: they stored the return value of the call to third party in a variable, which they never checked. That's an enormous step forward already, isn't it?

              D Offline
              D Offline
              David A Gray
              wrote on last edited by
              #6

              Reading this thread reminds me of a short story that I read long ago. I can no longer remember whether I was in high school or college; the only reason that has any relevance is that I have forgotten the story, but not its title, "Insert Flap A and Throw It Away." I have learned, and am periodically reminded of its importance, that if a function returns a value, even if it is poop, you would do well to check it. After all, if the author thought it was important enough to return, who am I to brush him off by ignoring it? Plenty of authors have written plenty of functions that return void. In all versions of BASIC, these are called Subs, short for Subroutines. Their author is effectively saying, "I have nothing to report; just trust me." A couple of weeks ago, I ran across a method that returns void that I wish didn't. The method in question, Console.WriteLine() would be much more useful if it returned a character count, along the lines of what you can get from printf(), but probably aren't. Almost every example I see that uses printf() doesn't bother with the return code. This is so prevalent that I hadn't given the matter any consideration until I started working with its buffered cousin, sprintf(). Along the way, I discovered that both have a return value of type int, which returns the number of characters written. While the newer "secure" print functions in the latest Visual C runtime library return minus one to indicate failure, even the old ones can be persuaded to print nothing and return zero.

              David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups