Partager via


C6318

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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

This warning indicates that if an exception occurs in the protected block of this structured exception handler, the exception will not 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 is not executed.

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 6318  
  {  
    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