I have a quick question about error checking. If I wish to check the parameters passed to a function, should I do this before calling the function, within the function or both? Should this choice be based on where I wish to catch and process the error? (Please refer to example below.)
In general, I would say check for errors in the function. If you don't, you'll end up having duplicate error checking code wherever you use the function. Depending on the situation, you may throw an exception or return a special/default value.