M
Mr Newbie
I am often in the situation where I want to act on the result of a function,
but a simple boolean is not enough. For example, I may have a function
called
isAuthorised ( User, Action ) as ?????
OK, this function may return a boolean, and if this is true, then no message
back is really required, but if it fails then some supporting message needs
to be returned to the calling code. As I see it there are a few options.
1.) Throw an exception with the message in ( But this tends to slow down
execution a little ?? )
2.) Return an enumeration type, but this is a little cumbersome because it
means I have to define all my possible return combinations against a number,
which could become messy.
3.) Add a third parameter called message which can be set to any error
message returned.
4.) Return a structure which contains a boolean and a string describing the
result.
Can I ask what you guys normally do in this situation, what is best
practice, pros and cons etc.
Thanks
Mr N
but a simple boolean is not enough. For example, I may have a function
called
isAuthorised ( User, Action ) as ?????
OK, this function may return a boolean, and if this is true, then no message
back is really required, but if it fails then some supporting message needs
to be returned to the calling code. As I see it there are a few options.
1.) Throw an exception with the message in ( But this tends to slow down
execution a little ?? )
2.) Return an enumeration type, but this is a little cumbersome because it
means I have to define all my possible return combinations against a number,
which could become messy.
3.) Add a third parameter called message which can be set to any error
message returned.
4.) Return a structure which contains a boolean and a string describing the
result.
Can I ask what you guys normally do in this situation, what is best
practice, pros and cons etc.
Thanks
Mr N