Enum RuleThrowingBehaviour
Enumerates the available scenarios in which a validator will throw an exception due to either failure or unexpected exceptions from validation rules.
Namespace: CSF.Validation
Assembly: CSF.Validation.Abstractions.dll
Syntax
public enum RuleThrowingBehaviour
Remarks
The default behaviour if this value is not specified upon the ResolvedValidationOptions is OnError. This is recommended for normal use.
The OnFailure behaviour is not recommended except for scenarios where the validated object is expected to be valid and where an invalid object represents an exceptional case. If you expect that the validated object could be invalid then use either OnError or Never to avoid throwing an exception for a 'normal' failure.
The OnFailure behaviour includes the behaviour specified by OnError.
When the Never behaviour is specified, no exception will be raised at the completion of validation. Rule results with outcomes of Errored will still cause the validation result to indicate failure but without throwing an exception.
The Never behaviour is not recommended unless it is expected that validation rules may raise uncaught exceptions. Under normal operation this would usually suggest bad design. The disadvantage of this approach is that it may hide logic errors and/or other problems because an unexpected exception will be treated very similarly to normal validation failures.
Fields
Name | Description |
---|---|
Never | The validator will not throw an exception under normal operation, even if validation rules raise uncaught exceptions. |
OnError | The validator will throw an exception at the completion of validation if any result has an outcome of Errored, such as when a rule raises an exception. |
OnFailure | The validator will throw an exception at any time when the validation fails, even if the reason for the failure was not exceptional. |