Link to home
Start Free TrialLog in
Avatar of rzvika3
rzvika3

asked on

Result Object

Hi!
It happens a lot of times that we call a method for doing something and we want to know both if the method operation result was ok (and if so, to know the returned value) or not ok.
I thought of creating a Result Class that will contain int (represents the result: success/failure) and an error message that will contain the error message in case of error and last, an Object that contain the Object result in case it was ok.
Is it ok to do so?
is it clear to understand the Result class' purpose and data members?
please comment.
Thank you very much.
Avatar of _lychee_
_lychee_

if your code doesn't produce 'error' results very often, i think the exception model is much clearer in terms of semantics... and it forces u to handle it...
Avatar of rzvika3

ASKER

I have this case:
I have created a class C, and the creation of an instance of it can throw a lot of Exception types.
I want to do a static method in C that either creates a C object or tells an error if something was wrong.
I think that using Result object can be useful in this case.

Exception itself has a message facility... so i still dun get the pt of the Result object...

Result tells if there's an error...
Exception tells if there's an error

Result contains error message if error
Exception can contain error msg if error

Result returns whatever
No exception is thrown, and all is well...

 nice comment by _lychee_
ASKER CERTIFIED SOLUTION
Avatar of isoBoy
isoBoy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial