micah
asked on
What to do when construction fails?
Lets say I have a constructor that does some operations, for some reason one or more of these operations fail. What is the best way to set some sort of error condition?
A a = new A("filename");
say the filename doesn't exist, now probably any operation I do with a will also fail. Do I use exceptions? Add a class function to check for valid creation?
I am not dealing with IO in any sort in my situation, just using it to clearify my problem
A a = new A("filename");
say the filename doesn't exist, now probably any operation I do with a will also fail. Do I use exceptions? Add a class function to check for valid creation?
I am not dealing with IO in any sort in my situation, just using it to clearify my problem
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is actually a third choice, but I would probably opt for one of the others. But the third choice is you can return an error code of some sort using a reference parameter.