Warning C6310

Illegal constant in exception filter can cause unexpected behavior

Remarks

This message indicates that an illegal constant was detected in the filter expression of a structured exception handler. The constants defined for use in the filter expression of a structured exception handler are:

  • EXCEPTION_CONTINUE_EXECUTION

  • EXCEPTION_CONTINUE_SEARCH

  • EXCEPTION_EXECUTE_HANDLER

These values are defined in the run-time header file excpt.h.

Using a constant that isn't in the preceding list can cause unexpected behavior.

Code analysis name: ILLEGALEXCEPTEXPRCONST

Example

The following code generates this warning:

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

BOOL LimitExceeded();

void fd( )
{
  __try
  {
    if (LimitExceeded())
    {
      RaiseException(EXCEPTION_ACCESS_VIOLATION,0,0,0);
    }
    else
    {
      // code
    }
  }
  __except (EXCEPTION_ACCESS_VIOLATION)
  {
    puts("Exception Occurred");
  }
}

To correct this warning, use the following code:

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

BOOL LimitExceeded();

void fd( )
{
  __try
  {
    if (LimitExceeded())
    {
      RaiseException(EXCEPTION_ACCESS_VIOLATION,0,0,0);
    }
    else
    {
      // code
    }
  }
  __except (GetExceptionCode()==EXCEPTION_ACCESS_VIOLATION ?
               EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
  {
    puts("Exception Occurred");
  }
}