Re: error handlling in recursive function




"David Resnick" <lndresnick@xxxxxxxxx> wrote in message
A third option might be to have a global variable (at file scope)
that gets set if an error occurs. Ok, global variables are EVIL,
but this may be one of the cases where their use can simplify
things a bit...

Sure, and a fourth is to pass down a pointer to a variable to use for
error reporting. I gave the answer I did because I interpreted his
question as being also how to reasonably unwind the stack of recursive
invocations when hitting an error condition...

MiniBasic has exactly this problem.
The solution is to have a sticky error. So once one error is set, all subsequent errors are suppressed. So the rest of the code can chug on, returning in its own good time - obviously you have to be a bit careful not to write to potentially null pointers and so on, but there is no reason to stop expression parsing jsut because a string wasn't allocated somewhere.

PS website contains important programming and scientific information. Someone please check availability for me.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

.