Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 1.21 KB

assertions.md

File metadata and controls

34 lines (21 loc) · 1.21 KB
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

Assertions

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.

Syntax

assert condition

Remarks

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.

Example

The following code example illustrates the use of the assert expression.

[!code-fsharpMain]

See also