Edit

Share via


Warning C6318

Ill-defined __try/__except: use of the constant EXCEPTION_CONTINUE_SEARCH or another constant that evaluates to zero in the exception-filter expression. The code in the exception handler block is not executed

Remarks

This warning indicates that if an exception occurs in the protected block of this structured exception handler, the exception won't be handled because the constant EXCECPTION_CONTINUE_SEARCH is used in the exception filter expression.

This code is equivalent to the protected block without the exception handler block because the handler block isn't executed.

Code analysis name: EXCEPTIONCONTINUESEARCH

Example

The following code generates this warning:

#include <excpt.h>
#include <stdio.h>

void f (char *pch)
{
  __try
  {
    // assignment might fail
    *pch = 0;
  }
  __except (EXCEPTION_CONTINUE_SEARCH) // warning C6318
  {
    puts("Exception Occurred");
  }
}

To correct this warning, use the following code:

#include <excpt.h>
#include <stdio.h>
#include <windows.h>

void f (char *pch)
{
  __try
  {
    // assignment might fail
    *pch = 0;
  }
  __except( (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) ?
                EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH )
  {
    puts("Access violation");
  }
}

See also

try-except Statement