I am writing a custom assertion macro, when assertion failed, this function is called
void _XLCAssertionFailedCritical(NSString *format, ...)
{
va_list ap;
va_start(ap, format);
// this suppose to throw exception
[NSException raise:NSInternalInconsistencyException format:format arguments:ap];
va_end(ap); // <---- this line is unreachable?
}
But I then realized that this function have a memory leak... va_end(ap);
is unreachable.
I can use other method to create and throw exception, but this method is just bugging me. It seems not possible to use it without memory leak?
I understand that exception is not something suppose to happen in normal control flow, but I still want to write memory-leak-free problem even under exceptional cases.
This method mean to be a convenient method so raise an exception with some format string can be simpler. But with the cost of a memory leak?