Class DomainException
The exception that is thrown when a domain model is not in a valid state.
public class DomainException : Exception, ISerializable
- Inheritance
-
DomainException
- Implements
- Inherited Members
Examples
Throw a DomainException when a domain invariant is violated to surface a domain-meaningful error that the application layer can map to an appropriate response.
using System;
using Savvyio.Domain;
namespace ExampleApp;
public sealed class DomainExceptionExample
{
public void ValidateOrder(int quantity)
{
try
{
EnsurePositiveQuantity(quantity);
}
catch (DomainException exception)
{
Console.WriteLine($"Domain violation: {exception.Message}");
throw;
}
}
private static void EnsurePositiveQuantity(int quantity)
{
if (quantity <= 0) { throw new DomainException("Order quantity must be greater than zero."); }
}
}
Constructors
DomainException()
Initializes a new instance of the DomainException class.
public DomainException()
DomainException(Exception)
Initializes a new instance of the DomainException class.
public DomainException(Exception innerException)
Parameters
innerExceptionExceptionThe exception that is the cause of the current exception.
DomainException(string, Exception)
Initializes a new instance of the DomainException class.
public DomainException(string message, Exception innerException = null)