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. Why not: // just shoot me!

Why not: // just shoot me!

Scheduled Pinned Locked Moved The Weird and The Wonderful
24 Posts 16 Posters 2 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.
  • E esaulsberry

    try { account.Save(); } catch { ; } //Not good! :mad:

    G Offline
    G Offline
    Gary Wheeler
    wrote on last edited by
    #6

    I'm impressed they wasted the energy on a surplus semicolon.

    Software Zen: delete this;

    E E 2 Replies Last reply
    0
    • G Gary Wheeler

      I'm impressed they wasted the energy on a surplus semicolon.

      Software Zen: delete this;

      E Offline
      E Offline
      englebart
      wrote on last edited by
      #7

      They might have a style rule that enforces: "catch block cannot be empty" Warning: Empty catch block. ftfy: ";"

      G 1 Reply Last reply
      0
      • E englebart

        They might have a style rule that enforces: "catch block cannot be empty" Warning: Empty catch block. ftfy: ";"

        G Offline
        G Offline
        Gary Wheeler
        wrote on last edited by
        #8

        ... which just demonstrates how misleading style enforcement can be.

        Software Zen: delete this;

        1 Reply Last reply
        0
        • G Gary Wheeler

          I'm impressed they wasted the energy on a surplus semicolon.

          Software Zen: delete this;

          E Offline
          E Offline
          esaulsberry
          wrote on last edited by
          #9

          :-D What kills me is the comment. It would have taken the same effort to say Logger.Log(ex);

          1 Reply Last reply
          0
          • E esaulsberry

            try { account.Save(); } catch { ; } //Not good! :mad:

            A Offline
            A Offline
            agolddog
            wrote on last edited by
            #10

            I'm trying (in vain so far) to think up any scenario where the context around this might make this o.k. For example, something like:

            int pageIndex = 0;
            try {
            pageIndex = int.TryParse(Request[pageNum])
            } catch (Exception e) {
            Logger.info("Page Index of " + Request[pageNum] + " invalid, using " + pageIndex.ToString());
            }

            (Of course, I'd use Int.TryParse instead and null-check the request variable) But, you get the idea--some scenario where you can continue to operate with default data given an unexpected condition. I can't think of any situation where the missing context makes it o.k. to swallow an exception trying whatever a Save operation does.

            E S 2 Replies Last reply
            0
            • A agolddog

              I'm trying (in vain so far) to think up any scenario where the context around this might make this o.k. For example, something like:

              int pageIndex = 0;
              try {
              pageIndex = int.TryParse(Request[pageNum])
              } catch (Exception e) {
              Logger.info("Page Index of " + Request[pageNum] + " invalid, using " + pageIndex.ToString());
              }

              (Of course, I'd use Int.TryParse instead and null-check the request variable) But, you get the idea--some scenario where you can continue to operate with default data given an unexpected condition. I can't think of any situation where the missing context makes it o.k. to swallow an exception trying whatever a Save operation does.

              E Offline
              E Offline
              esaulsberry
              wrote on last edited by
              #11

              In this case it's just plain sloppy, lazy, and wrong. It should log and throw, allowing the error to propagate to the global error handler. The object's been validated so if the save fails it's a critical failure somewhere in the system, like the database is down. Eating the error when a save fails is never the right thing to do. The user blissfully goes about their business because the save "worked" but it didn't. Wrong, wrong, wrong.

              1 Reply Last reply
              0
              • E esaulsberry

                try { account.Save(); } catch { ; } //Not good! :mad:

                S Offline
                S Offline
                StatementTerminator
                wrote on last edited by
                #12

                Looks to me like the original programmer was too lazy to handle an exception, and another programmer came along and added the helpful "Not good!" comment, and left it like that. I don't know which programmer to hate more. Five bucks says that account.Save() has a return value indicating success.

                1 Reply Last reply
                0
                • A agolddog

                  I'm trying (in vain so far) to think up any scenario where the context around this might make this o.k. For example, something like:

                  int pageIndex = 0;
                  try {
                  pageIndex = int.TryParse(Request[pageNum])
                  } catch (Exception e) {
                  Logger.info("Page Index of " + Request[pageNum] + " invalid, using " + pageIndex.ToString());
                  }

                  (Of course, I'd use Int.TryParse instead and null-check the request variable) But, you get the idea--some scenario where you can continue to operate with default data given an unexpected condition. I can't think of any situation where the missing context makes it o.k. to swallow an exception trying whatever a Save operation does.

                  S Offline
                  S Offline
                  StatementTerminator
                  wrote on last edited by
                  #13

                  I can think of situations where it might be appropriate to do something like that. For instance, suppose you are implementing a "like" button or something similar. It's not critical that it works and let's assume that it's unreliable for reasons beyond the programmer's control, like maybe it depends on an external service which is not always available. So in that case maybe it's OK to swallow the exception since it's not unusual and nothing will really break if it fails, so you just silently fail and the user can try again if they want. There aren't many situations like this in programming though, and you still should probably log the exceptions. I'm pretty sure that something like account.Save() is a bit too important to treat this way, though.

                  L 1 Reply Last reply
                  0
                  • E esaulsberry

                    try { account.Save(); } catch { ; } //Not good! :mad:

                    R Offline
                    R Offline
                    RafagaX
                    wrote on last edited by
                    #14

                    Well if saving doesn't work now, it could work later... ;P

                    CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

                    K 1 Reply Last reply
                    0
                    • E esaulsberry

                      try { account.Save(); } catch { ; } //Not good! :mad:

                      S Offline
                      S Offline
                      sparkytheone
                      wrote on last edited by
                      #15

                      If in the account class the Save method looked like this there might be a scenario where the eating of exceptions is fine: try { // Some code to save the record to the db .... } catch(Exception ex) { logger.Log(ex); throw; }

                      1 Reply Last reply
                      0
                      • R RafagaX

                        Well if saving doesn't work now, it could work later... ;P

                        CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

                        K Offline
                        K Offline
                        KP Lee
                        wrote on last edited by
                        #16

                        RafagaX wrote:

                        Well if saving doesn't work now, it could work later...

                        Oh, yea! Really user friendly. I ask to save, it works fine. Except I don't know if it worked or not. So now I've got to retrieve the data. If it is retrieved, fine, it worked. If not, then I get to save again and then check again and...

                        1 Reply Last reply
                        0
                        • E esaulsberry

                          try { account.Save(); } catch { ; } //Not good! :mad:

                          P Offline
                          P Offline
                          Pablo Aliskevicius
                          wrote on last edited by
                          #17

                          I've read somewhere that this code is equivalent to:

                          try
                          {
                          // account.Save(); // If this can fail silently, then why bother?
                          }
                          catch { ; } //Not good!

                          Then again, a LART would be more educational. ;)

                          Pablo. "Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).

                          E 1 Reply Last reply
                          0
                          • P Pablo Aliskevicius

                            I've read somewhere that this code is equivalent to:

                            try
                            {
                            // account.Save(); // If this can fail silently, then why bother?
                            }
                            catch { ; } //Not good!

                            Then again, a LART would be more educational. ;)

                            Pablo. "Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).

                            E Offline
                            E Offline
                            esaulsberry
                            wrote on last edited by
                            #18

                            A fantastic point.

                            1 Reply Last reply
                            0
                            • S StatementTerminator

                              I can think of situations where it might be appropriate to do something like that. For instance, suppose you are implementing a "like" button or something similar. It's not critical that it works and let's assume that it's unreliable for reasons beyond the programmer's control, like maybe it depends on an external service which is not always available. So in that case maybe it's OK to swallow the exception since it's not unusual and nothing will really break if it fails, so you just silently fail and the user can try again if they want. There aren't many situations like this in programming though, and you still should probably log the exceptions. I'm pretty sure that something like account.Save() is a bit too important to treat this way, though.

                              L Offline
                              L Offline
                              Lutoslaw
                              wrote on last edited by
                              #19

                              StatementTerminator wrote:

                              implementing a "like" button or something similar. It's not critical that it works

                              Man, people split up because of a 'like' button. You don't 'like' in time -- you loose. It IS crtical. :rolleyes:

                              Greetings - Jacek

                              S 1 Reply Last reply
                              0
                              • L Lutoslaw

                                StatementTerminator wrote:

                                implementing a "like" button or something similar. It's not critical that it works

                                Man, people split up because of a 'like' button. You don't 'like' in time -- you loose. It IS crtical. :rolleyes:

                                Greetings - Jacek

                                S Offline
                                S Offline
                                StatementTerminator
                                wrote on last edited by
                                #20

                                That's OK, people who care about "like" buttons should be ostracized anyway. On a side note, if I hear someone at my organization say one more time that our site needs to be more like Facebook, I'm going to garrote myself with a Cat5 cable.

                                L 1 Reply Last reply
                                0
                                • S StatementTerminator

                                  That's OK, people who care about "like" buttons should be ostracized anyway. On a side note, if I hear someone at my organization say one more time that our site needs to be more like Facebook, I'm going to garrote myself with a Cat5 cable.

                                  L Offline
                                  L Offline
                                  Lutoslaw
                                  wrote on last edited by
                                  #21

                                  Well, CP seems to go in that direction, too... It is a matter of time when it becomes "CodeBook". If it makes you feel better, I can vote you down :laugh:

                                  Greetings - Jacek

                                  L 1 Reply Last reply
                                  0
                                  • E esaulsberry

                                    try { account.Save(); } catch { ; } //Not good! :mad:

                                    K Offline
                                    K Offline
                                    Konstardiy from Tbilisi
                                    wrote on last edited by
                                    #22

                                    I will not shoot you, but support team will do, after over 9000 calls from angry users...

                                    1 Reply Last reply
                                    0
                                    • L Lutoslaw

                                      Well, CP seems to go in that direction, too... It is a matter of time when it becomes "CodeBook". If it makes you feel better, I can vote you down :laugh:

                                      Greetings - Jacek

                                      L Offline
                                      L Offline
                                      Luiz Monad
                                      wrote on last edited by
                                      #23

                                      This is why I hate the facebook, I cannot hate things, can only like things. How in the world I am supposed to only like things.

                                      L 1 Reply Last reply
                                      0
                                      • L Luiz Monad

                                        This is why I hate the facebook, I cannot hate things, can only like things. How in the world I am supposed to only like things.

                                        L Offline
                                        L Offline
                                        Lutoslaw
                                        wrote on last edited by
                                        #24

                                        Luiz Felipe Stangarlin wrote:

                                        This is why I hate the facebook, I cannot hate things, can only like things. How in the world I am supposed to only like things.

                                        I think exactly opposite. While I'm not a huge fan of a facebook, this particular feature is fine for me. Whereas I do dislike various things, a non-existance of downvoting mechanism forces me to express the dislike in a commentary (hopefully constructive). No downvoting makes the website more positive, which is a desired feature for a social network. We all have enough univoters in the real life... Anyway, there are a lot of "hatred groups" on FB. Giving a 'like' to them is a way to express hatred, if you really need to.

                                        Greetings - Jacek

                                        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