Upravit

Sdílet prostřednictvím


GetExceptionCode macro

Retrieves a code that identifies the type of exception that occurs. The function can be called only from within the filter expression or exception-handler block of an exception handler.

Note

The Microsoft C/C++ Optimizing Compiler interprets this function as a keyword, and its use outside the appropriate exception-handling syntax generates a compiler error.

 

Syntax

DWORD GetExceptionCode(void);

Parameters

This macro has no parameters.

Return value

The return value identifies the type of exception. The following table identifies the exception codes that can occur due to common programming errors. These values are defined in WinBase.h and WinNT.h.

Return code Description
EXCEPTION_ACCESS_VIOLATION
The thread attempts to read from or write to a virtual address for which it does not have access.
This value is defined as STATUS_ACCESS_VIOLATION.
EXCEPTION_ARRAY_BOUNDS_EXCEEDED
The thread attempts to access an array element that is out of bounds, and the underlying hardware supports bounds checking.
This value is defined as STATUS_ARRAY_BOUNDS_EXCEEDED.
EXCEPTION_BREAKPOINT
A breakpoint is encountered.
This value is defined as STATUS_BREAKPOINT.
EXCEPTION_DATATYPE_MISALIGNMENT
The thread attempts to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries, 32-bit values on 4-byte boundaries, and so on.
This value is defined as STATUS_DATATYPE_MISALIGNMENT.
EXCEPTION_FLT_DENORMAL_OPERAND
One of the operands in a floating point operation is denormal. A denormal value is one that is too small to represent as a standard floating point value.
This value is defined as STATUS_FLOAT_DENORMAL_OPERAND.
EXCEPTION_FLT_DIVIDE_BY_ZERO
The thread attempts to divide a floating point value by a floating point divisor of 0 (zero).
This value is defined as STATUS_FLOAT_DIVIDE_BY_ZERO.
EXCEPTION_FLT_INEXACT_RESULT
The result of a floating point operation cannot be represented exactly as a decimal fraction.
This value is defined as STATUS_FLOAT_INEXACT_RESULT.
EXCEPTION_FLT_INVALID_OPERATION
A floating point exception that is not included in this list.
This value is defined as STATUS_FLOAT_INVALID_OPERATION.
EXCEPTION_FLT_OVERFLOW
The exponent of a floating point operation is greater than the magnitude allowed by the corresponding type.
This value is defined as STATUS_FLOAT_OVERFLOW.
EXCEPTION_FLT_STACK_CHECK
The stack has overflowed or underflowed, because of a floating point operation.
This value is defined as STATUS_FLOAT_STACK_CHECK.
EXCEPTION_FLT_UNDERFLOW
The exponent of a floating point operation is less than the magnitude allowed by the corresponding type.
This value is defined as STATUS_FLOAT_UNDERFLOW.
EXCEPTION_GUARD_PAGE
The thread accessed memory allocated with the PAGE_GUARD modifier.
This value is defined as STATUS_GUARD_PAGE_VIOLATION.
EXCEPTION_ILLEGAL_INSTRUCTION
The thread tries to execute an invalid instruction.
This value is defined as STATUS_ILLEGAL_INSTRUCTION.
EXCEPTION_IN_PAGE_ERROR
The thread tries to access a page that is not present, and the system is unable to load the page. For example, this exception might occur if a network connection is lost while running a program over a network.
This value is defined as STATUS_IN_PAGE_ERROR.
EXCEPTION_INT_DIVIDE_BY_ZERO
The thread attempts to divide an integer value by an integer divisor of 0 (zero).
This value is defined as STATUS_INTEGER_DIVIDE_BY_ZERO.
EXCEPTION_INT_OVERFLOW
The result of an integer operation creates a value that is too large to be held by the destination register. In some cases, this will result in a carry out of the most significant bit of the result. Some operations do not set the carry flag.
This value is defined as STATUS_INTEGER_OVERFLOW.
EXCEPTION_INVALID_DISPOSITION
An exception handler returns an invalid disposition to the exception dispatcher. Programmers using a high-level language such as C should never encounter this exception.
This value is defined as STATUS_INVALID_DISPOSITION.
EXCEPTION_INVALID_HANDLE
The thread used a handle to a kernel object that was invalid (probably because it had been closed.)
This value is defined as STATUS_INVALID_HANDLE.
EXCEPTION_NONCONTINUABLE_EXCEPTION
The thread attempts to continue execution after a non-continuable exception occurs.
This value is defined as STATUS_NONCONTINUABLE_EXCEPTION.
EXCEPTION_PRIV_INSTRUCTION
The thread attempts to execute an instruction with an operation that is not allowed in the current computer mode.
This value is defined as STATUS_PRIVILEGED_INSTRUCTION.
EXCEPTION_SINGLE_STEP
A trace trap or other single instruction mechanism signals that one instruction is executed.
This value is defined as STATUS_SINGLE_STEP.
EXCEPTION_STACK_OVERFLOW
The thread uses up its stack.
This value is defined as STATUS_STACK_OVERFLOW.
STATUS_UNWIND_CONSOLIDATE
A frame consolidation has been executed.

 

Remarks

The GetExceptionCode function can be called only from within the filter expression or exception-handler block of an exception handler. The filter expression is evaluated if an exception occurs during execution of the __try block, and it determines whether or not the __except block is executed.

The filter expression can invoke a filter function. The filter function cannot call GetExceptionCode. However, the return value of GetExceptionCode can be passed as a parameter to a filter function. The return value of the GetExceptionInformation function can also be passed as a parameter to a filter function. GetExceptionInformation returns a pointer to a structure that includes the exception code information.

When nested handlers exist, each filter expression is evaluated until one is evaluated as EXCEPTION_EXECUTE_HANDLER or EXCEPTION_CONTINUE_EXECUTION. Each filter expression can invoke GetExceptionCode to get the exception code.

The exception code returned is the code generated by a hardware exception, or the code specified in the RaiseException function for a software generated exception.

When handling the breakpoint exception, it is important to increment the instruction pointer in the context record to continue from this exception.

Examples

For an example, see Using an Exception Handler.

Requirements

Requirement Value
Minimum supported client
Windows XP [desktop apps only]
Minimum supported server
Windows Server 2003 [desktop apps only]

See also

GetExceptionInformation

RaiseException

Structured Exception Handling Functions

Structured Exception Handling Overview