error handling
A common scenario:In the cmod module I am working on, all the library functions I call return a special error struct, and then I can call a function to get a malloc'd char *err describing the error. Calling Pike_error(err) will end execution of my function and leave me with a memory leak right? How can I throw an error and then still free the string? Or do I have to just return 0 or 1 and then have an error() function to describe what went wrong?Grubba provides the following options (what do they mean???): void f_static_msg(INT32 args) { char *err_msg = ...; push_error(err_msg); free(err_msg); free_svalue(& throw_value); move_svalue (&throw_value, --Pike_sp); throw_severity = THROW_ERROR; in_error=0; pike_throw(); /* Hope someone is catching, or we will be out of balls. */ } void f_dynamic_msg(INT32 args) { char *err_msg = ...; ONERROR tmp; SET_ONERROR(tmp, free, err_msg); pike_error("Something went wrong: %sn", err_msg); /* NOT_REACHED */ CALL_AND_UNSET_ONERROR(tmp); } Powered by PikeWiki2 |
|||
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University |