Re: error handlling in recursive function
- From: David Resnick <lndresnick@xxxxxxxxx>
- Date: Fri, 30 May 2008 06:51:44 -0700 (PDT)
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
.
- Follow-Ups:
- Re: error handlling in recursive function
- From: Jens Thoms Toerring
- Re: error handlling in recursive function
- References:
- error handlling in recursive function
- From: pereges
- error handlling in recursive function
- Prev by Date: Re: Expanding buffer - response to "Determine the size of malloc" query
- Next by Date: Re: passing copy of a pointer to a variable vs passing the copy
- Previous by thread: error handlling in recursive function
- Next by thread: Re: error handlling in recursive function
- Index(es):
Relevant Pages
|