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 bother with any other exception data? The message should suffice.

Why bother with any other exception data? The message should suffice.

Scheduled Pinned Locked Moved The Weird and The Wonderful
tutorialquestion
7 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.
  • Y Offline
    Y Offline
    yiangos
    wrote on last edited by
    #1

    try
    {
    //do stuff that may fail
    }
    catch (Exception e)
    {
    throw new Exception(e.Message);
    }

    This is from an online tutorial I recently came across (thankfully not in CP). Apparently if something goes wrong, one can get ALL the information one needs from the exception message. Why bother with stacktrace etc... ... or that's what the author thought, anyway.

    Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

    S Z 2 Replies Last reply
    0
    • Y yiangos

      try
      {
      //do stuff that may fail
      }
      catch (Exception e)
      {
      throw new Exception(e.Message);
      }

      This is from an online tutorial I recently came across (thankfully not in CP). Apparently if something goes wrong, one can get ALL the information one needs from the exception message. Why bother with stacktrace etc... ... or that's what the author thought, anyway.

      Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

      S Offline
      S Offline
      Sentenryu
      wrote on last edited by
      #2

      "An error has occurred, see the inner exception for details."

      I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

      Y 1 Reply Last reply
      0
      • Y yiangos

        try
        {
        //do stuff that may fail
        }
        catch (Exception e)
        {
        throw new Exception(e.Message);
        }

        This is from an online tutorial I recently came across (thankfully not in CP). Apparently if something goes wrong, one can get ALL the information one needs from the exception message. Why bother with stacktrace etc... ... or that's what the author thought, anyway.

        Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

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

        Quote:

        //do stuff that may fail

        Well there's the real problem. Why would you purposely write code that may fail. Write it to not fail. Duh!

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

        L B 2 Replies Last reply
        0
        • Z ZurdoDev

          Quote:

          //do stuff that may fail

          Well there's the real problem. Why would you purposely write code that may fail. Write it to not fail. Duh!

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

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

          I agree -- and not as a joke. In general code should not fail*. * -- in case you see my code fail: it was by design.

          Greetings - Jacek

          Y 1 Reply Last reply
          0
          • L Lutoslaw

            I agree -- and not as a joke. In general code should not fail*. * -- in case you see my code fail: it was by design.

            Greetings - Jacek

            Y Offline
            Y Offline
            yiangos
            wrote on last edited by
            #5

            Continuing on your serious note: the code per se, should not fail, I agree. But the final program may fail at times. Say you have a web request in there, and any of the following occurs: (a) the remote server times out (e.g. the server is offline) (b) the remote server has a bug, returning a 500 error (c) the remote server cannot find the requested resource, returning a 404 error (d) the remote server forbids access to the requested resource, returning a 403 error Any of the above results in the web request throwing an exception in YOUR application, but your code is not to blame. So there is a chance that a bug-free program CAN fail. That's why you should have error handling and meaningful error reporting.

            Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

            1 Reply Last reply
            0
            • S Sentenryu

              "An error has occurred, see the inner exception for details."

              I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"

              Y Offline
              Y Offline
              yiangos
              wrote on last edited by
              #6

              Yeah my point exactly. I'd done that same mistake myself, and thankfully it never got past the testing phase: I got that exact error message, and there was no inner exception to see :), so after a bit of digging, I simply changed my

              throw new Exception(ex.Message);

              to

              throw;

              (Of course, I had an error logging call just before that, otherwise the entire catch block wouldn't make much sense...) I was just very (unpleasantly) surprised to come across such a basic coding mistake in an online tutorial.

              Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)

              1 Reply Last reply
              0
              • Z ZurdoDev

                Quote:

                //do stuff that may fail

                Well there's the real problem. Why would you purposely write code that may fail. Write it to not fail. Duh!

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

                B Offline
                B Offline
                Bill_Hallahan
                wrote on last edited by
                #7

                Bugs happen.

                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