Reason Property in ConstraintViolationException

Tags: v9preview5 v9

The exception ConstraintViolationException has been enhanced with the Reason property to provide details on the reason for the constraint violation.

Reasons for Violations

Example Usage

try
{
    // Order operation
}
catch (ConstraintViolationException ex)
{
    switch (ex.Reason)
    {
        case ConstraintViolationReason.ProductExcludedFromMenu:
            // Handling excluded product from menu
            break;
        case ConstraintViolationReason.ModifierUsing:
            // Handling errors with modifiers
            break;
    }
}

See also