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. General Programming
  3. C / C++ / MFC
  4. Exception handling or return value

Exception handling or return value

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
6 Posts 3 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.
  • R Offline
    R Offline
    Raj Prathap
    wrote on last edited by
    #1

    Hi there, Please specify how to decide whether to go for return codes or exception handling. When is exception handling preferred over returning a specific error code. Thanks in advance, Raja Pratap

    CPalliniC 1 Reply Last reply
    0
    • R Raj Prathap

      Hi there, Please specify how to decide whether to go for return codes or exception handling. When is exception handling preferred over returning a specific error code. Thanks in advance, Raja Pratap

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      IMHO you need a decision between throwing an exception or returning a specific error code. If it is as above stated, then I think: (1) If it's your own application (entirely developed by you) then you can (almost) safely rely on return error codes, since you know that calling methods must always check the return values. (2) If your're working in team then throw, throw, throw: never trust your mates coding neatness!!! Hope that helps. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      R 1 Reply Last reply
      0
      • CPalliniC CPallini

        IMHO you need a decision between throwing an exception or returning a specific error code. If it is as above stated, then I think: (1) If it's your own application (entirely developed by you) then you can (almost) safely rely on return error codes, since you know that calling methods must always check the return values. (2) If your're working in team then throw, throw, throw: never trust your mates coding neatness!!! Hope that helps. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        R Offline
        R Offline
        Raj Prathap
        wrote on last edited by
        #3

        Thank you for your response Pillani. But still I'm not clear, why return codes are not suitable when we work as team.

        N CPalliniC 2 Replies Last reply
        0
        • R Raj Prathap

          Thank you for your response Pillani. But still I'm not clear, why return codes are not suitable when we work as team.

          N Offline
          N Offline
          Nelek
          wrote on last edited by
          #4

          Hi, I think it is because you can not be totally sure about what the others will do. If they get an assertion, they have to solve something, if they have a return code, they can make nothing about or even don't realize about the error. And then error will be cumulating themselves until it would be too difficult to correct the program.

          Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

          1 Reply Last reply
          0
          • R Raj Prathap

            Thank you for your response Pillani. But still I'm not clear, why return codes are not suitable when we work as team.

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            Raj Prathap wrote:

            But still I'm not clear, why return codes are not suitable when we work as team.

            Well, suppose you have a method returning failure. If the caller doesn't check the return value and continues execution, maybe some disaster is along the way. On the other hand, throwing an exception, you force the caller to handle it or, anyway, the execution will be stopped. Now, if the caller is a member of you team (and not yourself) then there is a chance that importance of return value is underestimated. Hope that helps :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            In testa che avete, signor di Ceprano?

            R 1 Reply Last reply
            0
            • CPalliniC CPallini

              Raj Prathap wrote:

              But still I'm not clear, why return codes are not suitable when we work as team.

              Well, suppose you have a method returning failure. If the caller doesn't check the return value and continues execution, maybe some disaster is along the way. On the other hand, throwing an exception, you force the caller to handle it or, anyway, the execution will be stopped. Now, if the caller is a member of you team (and not yourself) then there is a chance that importance of return value is underestimated. Hope that helps :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              R Offline
              R Offline
              Raj Prathap
              wrote on last edited by
              #6

              Thanks Pallini, That answers my question.

              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