Hello -
What's a good way to return an error status to the caller of a utility method? I have a class that stores and retrieves objects. During the operations, several errors can occur. The team prefers that these methods do not throw exceptions, but instead return error codes somehow. Here's the current methods (names changed to protect idiots):
boolean storeObject(Object data);
Object getObject(SomeCriteria stuff);
Object[] getAllObjects();
Currently, storeObject returns false on fail, the others return null on fail. We want to return a meaningful status code so the caller can take appropriate action. Should we do something like this?
final SUCCESS=0;
final NOT_FOUND=1;
final DISK_FULL=2;
etc
short storeObject(Object data);
short getObject(SomeCriteria stuff, list objs);
short getAllObjects(list objs);
Problem with above is the caller will have to provide an empty list prior to calling. Some team members complain that this is a messy interface.
Also, it's possible that several different types of errors can occur on the getAll, (we have 1000 objs, 998 are good, 1 has bad data, 1 is invalid for another reason). So it was suggested:
short getAllObject(list obj, list errs);
Help! All advice is welcome.
Thanks,
lizard43
What's a good way to return an error status to the caller of a utility method? I have a class that stores and retrieves objects. During the operations, several errors can occur. The team prefers that these methods do not throw exceptions, but instead return error codes somehow. Here's the current methods (names changed to protect idiots):
boolean storeObject(Object data);
Object getObject(SomeCriteria stuff);
Object[] getAllObjects();
Currently, storeObject returns false on fail, the others return null on fail. We want to return a meaningful status code so the caller can take appropriate action. Should we do something like this?
final SUCCESS=0;
final NOT_FOUND=1;
final DISK_FULL=2;
etc
short storeObject(Object data);
short getObject(SomeCriteria stuff, list objs);
short getAllObjects(list objs);
Problem with above is the caller will have to provide an empty list prior to calling. Some team members complain that this is a messy interface.
Also, it's possible that several different types of errors can occur on the getAll, (we have 1000 objs, 998 are good, 1 has bad data, 1 is invalid for another reason). So it was suggested:
short getAllObject(list obj, list errs);
Help! All advice is welcome.
Thanks,
lizard43