Share via


The NT_ASSERT macro tests an expression. If the expression is false, the macro raises a STATUS_ASSERTION_FAILURE exception and gives you the option of ignoring the exception, handling the exception, or breaking into the kernel debugger.




  • Expression
    Specifies any logical expression.

Return value



The NT_ASSERT macro will be included in your binary only if your code is compiled for a debug configuration. Once your driver is built, NT_ASSERT will work properly regardless of whether your driver is run on the checked build or on the free build of Windows. Unlike the ASSERT macro, the NT_ASSERT macro stores the Expression with the symbol information in the program database (PDB) file. The kernel debugger extracts the Expression and symbol information from the PDB file and also provides additional built-in assertion-handling support. When triggered, the NT_ASSERT macro can break into the debugger immediately, so the valuable state information that led up to the assertion failure is usually intact in the context reported to the debugger.

If Expression evaluates to TRUE, this routine has no effect.

If Expression evaluates to FALSE, and debugging is enabled and a debugger is connected, a message is displayed in the Debugger Command window. The message contains the source-code string of Expression, the path of the source-code file, and the line number of the instruction that called the macro. At this point, you can use debugging commands to ignore the exception, to handle the exception, or to break into the debugger. Use the ah (Assertion Handling) commands to ignore the STATUS_ASSERTION_FAILURE exception or to break into the debugger. You can also use the gh (Go with Exception Handled) or gn (Go with Exception Not Handled) debugger commands to continue execution.

If Expression evaluates to FALSE and debugging is not enabled, or debugging is enabled but the debugger is not connected, the failed assert will not be reported (although assertion checking will still be performed). If you are developing a driver and want to deterministically break into the debugger if one is enabled but not connected, you can use DbgBreakPoint statements in your code. For more information, see Controlling Exceptions and Events.

The NT_ASSERT macro can also be called as NT_VERIFY. The difference is that NT_VERIFY always evaluates its argument, while NT_ASSERT only evaluates its argument when you have compiled your code for a debug configuration. That is, when you compile your code using a debug configuration (DBG is defined), NT_VERIFY(expression) is equivalent to NT_ASSERT(expression). When you compile your code using a release configuration (DBG is not defined), NT_VERIFY(expression) is equivalent to (expression), while NT_ASSERT(expression) does nothing.


Target platform



Available in Microsoft Windows Vista and later.


Wdm.h (include Wdm.h)

See also





Send comments about this topic to Microsoft