From: Brian D. <br...@de...> - 2007-04-09 20:03:32
|
anandnld wrote: > In my third file I will call that function by passing various inputs > and wants to call atleast 10 times and want to check for the output from > that function as correct or wrong. > > By checking as like that, in between if any runtime error occurred > entire program crashes. How can handle it without crashing...... The best you can do is install your own exception handler that executes in the case where getValue dereferences NULL and display some message that says "getValue is crappy and needs to be fixed". You might be able to unwind to the frame of the faulting getValue's caller, but I'm not sure how that would be accomplished just with the win32 API and without compiler support for __try/__except. I suppose you could do this with setjmp/longjmp, actually. Something along the lines of: static jmp_buf context; LONG WINAPI MyExceptionFilter (LPEXCEPTION_POINTERS ExceptionInfo) { longjmp (context, 1); } void caller_of_crappy_getValue (...) { ... LPTOP_LEVEL_EXCEPTION_FILTER prev = SetUnhandledExceptionFilter (MyExceptionFilter); if (setjmp (context) == 0) { ret = getValue (...); } else { /* Do whatever it is you want to do to indicate that getValue faulted. */ } SetUnhandledExceptionFilter (prev); ... } I have no idea if this construct (specifically, exiting from an exception filter through longjmp instead of returning) is kosher or not, so it may be that this royally trashes the stack or something. Brian |