say i have a class which the user can make an object of by passing in 2 parameters. If the parameters entered are wrong how should i handle this?
1.) should i try to create the object,and then do the checking in the constructor? if the arguments are invalid then should i cancel creation(if possible) or set the arguments to a dummy value(for example all -1 for int variables and all "zzzzz" for string variables?
2.) should i check the user arguments before the creation of the class begins? for example.
if (validArguments)
{
//create object
}
else
{
//do not create the object
}
the statement in number 2 seems reasonable to me,but what if i make a class that i want to publish for others to use. I i used solution number 2. I would have no error checking for my class! and user's would have to make their own error checking functions for it.
if i choose statement number 1(which would make my class better because it has built in error checking) i have no idea how to deal with the invalid data.
any suggestions would be greatly appreciated. -thx