다음을 통해 공유


PREfast Warning 310 (Windows CE 5.0)

Send Feedback

310 - Illegal constant in exception filter.
Question: Did you intend to test this constant against GetExceptionCode()?

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 C run-time header except.h.

Using a constant not in the previous list can lead to unexpected behavior. In the following example, use of EXCEPTION_ACCESS_VIOLATION in the filter expression is treated as EXCEPTION_CONTINUE_EXECUTION. This leads to the following behavior:

  • If the exception is triggered by the call to RaiseException, execution continues after the exception and writes at the out-of-range address.
  • If an exception is occurs because Handle is an invalid pointer, an infinite loop results, because execution is continued at the instruction that resulted in the exception (resulting in another exception that is handled the same way, creating an infinite loop).

In either case, the actual handler statement is never executed. The return statement is dead code.

Example

Defective Source

#define LIMIT   0x7fff0000

__try {

    if (Handle >= Limit) {
        RaiseException(EXCEPTION_ACCESS_VIOLATION);
    }

    *Handle = NewValue;

} __except (EXCEPTION_ACCESS_VIOLATION) {
    return EXCEPTION_ACCESS_VIOLATION;
}

Corrected Source

#define LIMIT   0x7fff0000

__try {

    if (Handle >= Limit) {
        RaiseException(EXCEPTION_ACCESS_VIOLATION);
    } 

    *Handle = NewValue;

} __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) {
    return EXCEPTION_ACCESS_VIOLATION;
}

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.