You should never use "error codes" in replacement of exceptions. Invention of exceptions made all non-exception method obsolete. It needs understanding of exception mechanism which goes above the regular paradigm of methods and calls: it jumps over the stack during propagation. Many do not understand its power and robustness. With error conditions or "codes" you would manually drag it over all your function. In your case, you should really use exceptions. Another reason is separation of concerns. Regular code separate, exceptions separate — that what structured exception handling can do and should not be misused.
There is a long-standing flame war about using exception for non-errors, even here at CodeProject. To me it is absolutely clear, it is possible. That was implied meaning put in the self-describing term "Exception" bt the inventors (Barbara Liskov at all, first applied to the CLU programming language). "Exception" means any exceptional situation. Classic example: "Reactor overheated". Nothing is at fault, but the situation is exceptional, processing is special. The same situation is with the invalid parameter.
You approach should be the Design by contract, see
http://en.wikipedia.org/wiki/Design_by_contract[
^]. In your case the requirement to stay withing the range
0..10
is called
precondition
, other components of contract can be
postconditions
and
invariants
. An adequate method of processing of violated precondition is throwing exception.
—SA