From: Walt B. <Wal...@jp...> - 2005-06-23 23:28:39
|
Garrett, David, How about something like this: #define OSSIM_ASSERT(assertion) ossimAssert(assertion,__LINE__) int ossimAssert(int assertion, int line) { if (assertion) return 1; if (assertionCheckingMode == throwUnsatisfiedAssertions) throw unsatisfiedAssertion(__LINE__); else if (assertionCheckingMode == notifyUnsatisfiedAssertions) notifyUnsatisfiedAssertion(__LINE__); // else assertionCheckingMode == justLogUnsatisfiedAssertions logUnsatisfiedAssertion(__LINE__); return 0; } Then use like this void useIndex(int idx) { if (! OSSIM_ASSERT(idx >=0)) idx = 0; // fix the bad idx continue using idx; } So to catch bad indices passed to useIndex while debugging, set the assertionCheckingMode to throwUnsatisfiedAssertions. Otherwise just log/notify bad indices and "fix" if possible. Walt At 12:53 PM 6/23/2005 -0700, Walt Bunch wrote: >A while ago, I worked on the VPF code and observed that the approach to >handling exceptional situations was to silently correct errors. For >example, if an out of range index, e.g. -1, is passed to a method, the >method silently forces that index to be in range, e.g. 0. BTW, that made >it challenging to find some bugs. > >I'm working on some different code (adding set methods to class >ossimNitfRpcATag). Should I continue with that silent correction idiom, or >throw exceptions, or do something else? Is there a convention among the >ossim developers, or does each have his own style? > >Thanks, >Walt |