Article ID: 153005
Article Last Modified on 7/5/2005
"Exiting a try-finally statement using a return statement or the longjmp run-time function is considered abnormal termination. It is illegal to jump into a __try statement, but legal to jump out of one."
/* Compile options needed:
*/
#include <stdio.h>
#include <stdlib.h>
//#include <setjmpex.h> // uncomment this line for the workaround
#include <setjmp.h> // comment this line out for the workaround
#include <windows.h>
CRITICAL_SECTION cs;
jmp_buf jmpbuf;
void main()
{
int i = 0, j;
int hits = 0;
if(setjmp(jmpbuf))
{
hits += 1;
i = 0;
printf("\n\n Jump.....\n\n");
}
while(1)
{
for(j = 0; j < 10; j++)
printf("%d ", i++);
_try
{
longjmp(jmpbuf, 1);
}
_finally
{
printf("\n\nInside finally....\n");
}
}
}
Keywords: kbprb KB153005