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