Skip to main content

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

objectExceptionValueObjectException

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

Every integration on a hot path (JSON, model binding, EF Core, Dapper) uses the TryCreate family instead, so this exception is reserved for programmer errors and for the explicit Create entry point.

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.