Skip to main content
Version: Preview (0.3.0-preview.205)

Class ValueObjectException

Namespace: AdCodicem.ValueObjects
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Thrown when a value object is constructed from a value that violates one of its rules.

[Serializable]
public class ValueObjectException : Exception, ISerializable

Inheritance​

object ← Exception ← ValueObjectException

Implements​

ISerializable

Inherited Members​

Exception.GetBaseException(), Exception.GetType(), Exception.ToString(), Exception.Data, Exception.HelpLink, Exception.HResult, Exception.InnerException, Exception.Message, Exception.Source, Exception.StackTrace, Exception.TargetSite, Exception.SerializeObjectState, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

The integrations that take outside input (JSON, model binding, FluentValidation, Dapper) use the TryCreate and TryParse family and report a refusal in their own terms. This exception comes from the explicit Create and Parse entry points and an explicit conversion, for code that treats a rejected value as a bug, and from a strict EF Core read, which goes through Create and fails the query.

Constructors​

ValueObjectException()​

Initializes a new instance of the class.

public ValueObjectException()

ValueObjectException(string)​

Initializes a new instance of the class.

public ValueObjectException(string message)

Parameters​

message string

Message describing the violated rule.

ValueObjectException(string, Exception)​

Initializes a new instance of the class.

public ValueObjectException(string message, Exception innerException)

Parameters​

message string

Message describing the violated rule.

innerException Exception

Cause of this exception.

ValueObjectException(string, Type?, string?, object?)​

Initializes a new instance of the class.

public ValueObjectException(string message, Type? valueObjectType, string? errorCode, object? attemptedValue)

Parameters​

message string

Message describing the violated rule.

valueObjectType Type?

Value object type that rejected the value.

errorCode string?

Stable, machine-readable code of the violated rule.

attemptedValue object?

Value that was rejected.

Properties​

AttemptedValue​

Gets the value that was rejected.

public object? AttemptedValue { get; }

Property Value​

object?

ErrorCode​

Gets the stable, machine-readable code of the violated rule.

public string? ErrorCode { get; }

Property Value​

string?

ValueObjectType​

Gets the value object type that rejected the value.

public Type? ValueObjectType { get; }

Property Value​

Type?

Methods​

Throw(Type, string, string, object?)​

Throws a describing a rejected value.

[DoesNotReturn]
public static void Throw(Type valueObjectType, string errorCode, string errorMessage, object? attemptedValue)

Parameters​

valueObjectType Type

Value object type that rejected the value.

errorCode string

Stable, machine-readable code of the violated rule.

errorMessage string

Human-readable description of the violated rule.

attemptedValue object?

Value that was rejected.

Exceptions​

ValueObjectException

Always.