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. The return a detailed error string but ignore its contents and assume it's only ever the failure case you expected to occur but couldn't be bothered to handle properly pattern

The return a detailed error string but ignore its contents and assume it's only ever the failure case you expected to occur but couldn't be bothered to handle properly pattern

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpsysadminsecurityregexquestion
10 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.
  • D Offline
    D Offline
    Dan Neely
    wrote on last edited by
    #1

    private void Frobinate()
    {
    string result = CreateRecord();
    if (result == "")
    {
    //Normal case
    }
    else
    {
    if (MessageBox.Show("Record already exists. Do you want to update it?", MessageBoxButtons.YesNo) == DialogResults.Yes)
    {
    UpdateExistingRecord();
    }
    }

    }

    private string CreateRecord()
    {
    try
    {
    //do stuff to create a new record. Throws an exception for duplicates.
    return "";
    }
    catch (Exception e)
    {
    return e.Message;
    }
    }

    This pattern is absolutely brillant because nothing else could ever cause a problem. Authentication can never be incorrect. The server can never be down. Bob can never be taking a break to oil the hamster wheels.

    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

    Z OriginalGriffO 2 Replies Last reply
    0
    • D Dan Neely

      private void Frobinate()
      {
      string result = CreateRecord();
      if (result == "")
      {
      //Normal case
      }
      else
      {
      if (MessageBox.Show("Record already exists. Do you want to update it?", MessageBoxButtons.YesNo) == DialogResults.Yes)
      {
      UpdateExistingRecord();
      }
      }

      }

      private string CreateRecord()
      {
      try
      {
      //do stuff to create a new record. Throws an exception for duplicates.
      return "";
      }
      catch (Exception e)
      {
      return e.Message;
      }
      }

      This pattern is absolutely brillant because nothing else could ever cause a problem. Authentication can never be incorrect. The server can never be down. Bob can never be taking a break to oil the hamster wheels.

      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      Give the guy a break. At least he did try. :)

      There are only 10 types of people in the world, those who understand binary and those who don't.

      OriginalGriffO 1 Reply Last reply
      0
      • Z ZurdoDev

        Give the guy a break. At least he did try. :)

        There are only 10 types of people in the world, those who understand binary and those who don't.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        You caught that then?

        The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        Z 1 Reply Last reply
        0
        • D Dan Neely

          private void Frobinate()
          {
          string result = CreateRecord();
          if (result == "")
          {
          //Normal case
          }
          else
          {
          if (MessageBox.Show("Record already exists. Do you want to update it?", MessageBoxButtons.YesNo) == DialogResults.Yes)
          {
          UpdateExistingRecord();
          }
          }

          }

          private string CreateRecord()
          {
          try
          {
          //do stuff to create a new record. Throws an exception for duplicates.
          return "";
          }
          catch (Exception e)
          {
          return e.Message;
          }
          }

          This pattern is absolutely brillant because nothing else could ever cause a problem. Authentication can never be incorrect. The server can never be down. Bob can never be taking a break to oil the hamster wheels.

          Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Never knew it was a pattern and had a name! I can start using it now...

          The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          D 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            You caught that then?

            The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

            Z Offline
            Z Offline
            ZurdoDev
            wrote on last edited by
            #5

            Well sure. I couldn't just throw it away.

            There are only 10 types of people in the world, those who understand binary and those who don't.

            OriginalGriffO 1 Reply Last reply
            0
            • Z ZurdoDev

              Well sure. I couldn't just throw it away.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              You could have made an exception in this case!

              The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                Never knew it was a pattern and had a name! I can start using it now...

                The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #7

                If you're looking for other interesting desings, might I suggest the thousand plus line OnClick() method with at least ten levels of indentation pattern. Remember methodcalls have a performance overhead, so inline everything no matter how many copies you end up with.

                Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                L B 2 Replies Last reply
                0
                • D Dan Neely

                  If you're looking for other interesting desings, might I suggest the thousand plus line OnClick() method with at least ten levels of indentation pattern. Remember methodcalls have a performance overhead, so inline everything no matter how many copies you end up with.

                  Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

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

                  An appropriate design pattern should be applied indeed. 10 levels of indentation is not good, even if they were hidden in methods. A loop over a list of conditions or strategies maybe. Besides, if we have a framework object Exception, then why return a part of it (Message) instead of a reference to the object itself (or null if no error)? Makes no sense to me. We should either return an error code or make it OO, depending on what is better in a given context. Mixing those two approaches is a bit... unusual. I am no expert, please correct if I'm wrong.

                  Greetings - Jacek

                  1 Reply Last reply
                  0
                  • D Dan Neely

                    If you're looking for other interesting desings, might I suggest the thousand plus line OnClick() method with at least ten levels of indentation pattern. Remember methodcalls have a performance overhead, so inline everything no matter how many copies you end up with.

                    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                    B Offline
                    B Offline
                    BillW33
                    wrote on last edited by
                    #9

                    Sadly, I know programmers who love to use that pattern. :sigh:

                    Just because the code works, it doesn't mean that it is good code.

                    D 1 Reply Last reply
                    0
                    • B BillW33

                      Sadly, I know programmers who love to use that pattern. :sigh:

                      Just because the code works, it doesn't mean that it is good code.

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #10

                      It wasn't a hypothetical for me either. X|

                      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                      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