I
Ian Lazarus
Greetings,
Is there a consensus as to the best way to report a programming error, for
example an out of bounds index value passed to a function? There are three
approaches that I can think of:
[1] (traditional) error return value
[2] error value in object
[2] exception
Below are examples of how they might be used by functions that check their
index parameter for for out of bounds.
// [1]
er = object.process_index(index);
assert(er == 0);
// [2]
object.process_index(index);
assert(object.error == 0);
// [3]
try { object.process_index(index); }
catch(...) { assert(false); }
Programming errors are, I assume, most likely found via asserts. If this is
the case, the cleanest approach seems to be approach [2]. This prevents
cluttering up the call with error types and limits those references to the
assert.
Thanks
Is there a consensus as to the best way to report a programming error, for
example an out of bounds index value passed to a function? There are three
approaches that I can think of:
[1] (traditional) error return value
[2] error value in object
[2] exception
Below are examples of how they might be used by functions that check their
index parameter for for out of bounds.
// [1]
er = object.process_index(index);
assert(er == 0);
// [2]
object.process_index(index);
assert(object.error == 0);
// [3]
try { object.process_index(index); }
catch(...) { assert(false); }
Programming errors are, I assume, most likely found via asserts. If this is
the case, the cleanest approach seems to be approach [2]. This prevents
cluttering up the call with error types and limits those references to the
assert.
Thanks