Re: error handlling in recursive function



On May 30, 9:22 am, pereges <Brol...@xxxxxxxxx> wrote:
How to to go about this ? Suppose a malloc inside a recursive function
has failed and you want to set the error flag and return it to the
calling function(the one which called the recursive function in the
first place)

Options seem to be:

1) Propagate the flag back through the stack of recursive functions,
checking for it at each invocation. This is the best way if you need
to, say, release resources in each invocation of the recursive
function, which seems possible given that you are mallocing in the
recursion.

2) Use setjmp (before entering recursion) and longjmp to hop back on
error.

n.b. this is a case where exception throwing is nice, as with minimal
fuss it gets you back to the level that wants to handle the error
cleaning up all in between. But as we're in C, not an option

-David
.



Relevant Pages

  • Debug my program please.
    ... I have an error in to recursive function aggiungiat first recursion. ... !character,allocatable:: Parola ... Reinizializzazione della parola if (.not. ...
    (comp.lang.fortran)
  • Re: error handlling in recursive function
    ... has failed and you want to set the error flag and return it to the ... calling function(the one which called the recursive function in the ... checking for it at each invocation. ... Use setjmp (before entering recursion) and longjmp to hop back on ...
    (comp.lang.c)
  • Re: Timing Rescordset
    ... The recursive function I am using first check to see if it has something, ... avoid levels of recursion that lack substantial advantage. ... XML authors use the same node name in a different heirarchy? ... To reconstruct, you'll have to query the db for each level, in much the same ...
    (microsoft.public.data.ado)
  • Re: error handlling in recursive function
    ... calling function(the one which called the recursive function in the ... checking for it at each invocation. ... recursion. ... Ok, global variables are EVIL, ...
    (comp.lang.c)
  • Re: Traversing shallow CTreeCtrl
    ... Why not write a recursive function ... that takes exactly on HTREEITEM ... number of levels usually ends up being more difficult than a simple recursion. ... LvlThreeNode = MyTree.GetNextItem; ...
    (microsoft.public.vc.mfc)