Thanks Nick, that is exactly what I need. I am still wrapping my mind around all the Clownfish objects in C stuff. :)
Em seg, 30 de mar de 2015 às 16:41, Nick Wellnhofer <[email protected]> escreveu: > On 30/03/2015 20:06, Bruno Albuquerque wrote: > > Actually i think I was not clear about what I need. How would I apply > > Err_trap for a higher level function? For example, a call to > Indexer_new() > > might fail under some circunstances and the program will exit due to > that, > > I would like for it not to exit immediately (for example, to be able to > do > > something else if the call fails). indexer_new() does nto accept a > context > > and it returns something when it works. > > Try something like: > > typedef struct { > Indexer *indexer; > } my_context_t; > > static void > try_create_indexer(void *arg) { > my_context_t *ctx = (my_context_t*)arg; > ctx->indexer = Indexer_new(); > } > > void > other_code() { > my_context_t ctx; > Err *error = Err_trap(try_create_indexer, &ctx); > > if (error != NULL) { > /* Handle error. */ > } > else { > /* Indexer created successfully. */ > Indexer *indexer = ctx.indexer; > } > } > > C doesn't support closures, so such a verbose solution is necessary. > > Nick > >
