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#
  4. What is the best way for Return Messages? Exceptions, return strings, return classes?

What is the best way for Return Messages? Exceptions, return strings, return classes?

Scheduled Pinned Locked Moved C#
questiontutoriallounge
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.
  • G Offline
    G Offline
    gokselm
    wrote on last edited by
    #1

    Hi, I want to ask a question about how to return messages from a general class. How should I warn the users. When something happened that must not be done what the object must do? The senario is, there are several classes. Each of them has specific functionality. It seems to me that the best way is defining a class that has properties like MessageID and and the Message. User can compare the MessageID with the const integers on the class to understand what happens and takes action. Is there a general approach? Kind Regards

    P S 2 Replies Last reply
    0
    • G gokselm

      Hi, I want to ask a question about how to return messages from a general class. How should I warn the users. When something happened that must not be done what the object must do? The senario is, there are several classes. Each of them has specific functionality. It seems to me that the best way is defining a class that has properties like MessageID and and the Message. User can compare the MessageID with the const integers on the class to understand what happens and takes action. Is there a general approach? Kind Regards

      P Offline
      P Offline
      Paul Watson
      wrote on last edited by
      #2

      From what I have seen everybody has a different opinion on this one. I say clean up and throw a descriptive exception, but there will undoubtedly be many who will say that is a bad idea and recommend output params or returning strings etc. But my vote is on exceptions :) regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?

      D H 2 Replies Last reply
      0
      • G gokselm

        Hi, I want to ask a question about how to return messages from a general class. How should I warn the users. When something happened that must not be done what the object must do? The senario is, there are several classes. Each of them has specific functionality. It seems to me that the best way is defining a class that has properties like MessageID and and the Message. User can compare the MessageID with the const integers on the class to understand what happens and takes action. Is there a general approach? Kind Regards

        S Offline
        S Offline
        Stephane Rodriguez
        wrote on last edited by
        #3

        The one that complies with FxCop[^]. ;)


        RSS feed

        D 1 Reply Last reply
        0
        • S Stephane Rodriguez

          The one that complies with FxCop[^]. ;)


          RSS feed

          D Offline
          D Offline
          David Stone
          wrote on last edited by
          #4

          FxCop rocks! Did you know it's included in the Longhorn SDK download? :)


          When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?" -Hockey on being a geek

          1 Reply Last reply
          0
          • P Paul Watson

            From what I have seen everybody has a different opinion on this one. I say clean up and throw a descriptive exception, but there will undoubtedly be many who will say that is a bad idea and recommend output params or returning strings etc. But my vote is on exceptions :) regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?

            D Offline
            D Offline
            David Stone
            wrote on last edited by
            #5

            Paul Watson wrote: But my vote is on exceptions Ditto. Exceptions are the best way to notify the class consumer of an error.


            When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?" -Hockey on being a geek

            1 Reply Last reply
            0
            • P Paul Watson

              From what I have seen everybody has a different opinion on this one. I say clean up and throw a descriptive exception, but there will undoubtedly be many who will say that is a bad idea and recommend output params or returning strings etc. But my vote is on exceptions :) regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              I cast my vote for exceptions, too. A callee can pass far more data about any errors that occur to its caller in a polymorphic way that would be difficult - if not stupid - to do with out params.

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              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