title | description | ms.date |
---|---|---|
Assertions |
Learn how to use the 'assert' expression as a debugging feature for testing expressions in the F# programming language. |
10/22/2019 |
The assert
expression is a debugging feature that you can use to test an expression. Upon failure in Debug mode, an assertion generates a system error dialog box.
assert condition
The assert
expression has type bool -> unit
.
The assert
function resolves to xref:System.Diagnostics.Debug.Assert%2A?displayProperty=nameWithType. This means its behavior is identical to having called xref:System.Diagnostics.Debug.Assert%2A?displayProperty=nameWithType directly.
Assertion checking is enabled only when you compile in Debug mode; that is, if the constant DEBUG
is defined. In the project system, by default, the DEBUG
constant is defined in the Debug configuration but not in the Release configuration.
The assertion failure error cannot be caught by using F# exception handling.
The following code example illustrates the use of the assert
expression.
[!code-fsharpMain]