Open sandboxFocus

Class ContractExceptionFactory

Base class for contract exception factories. Implements the chain of responsibility between concrete exception factories.

Inheritance
ContractExceptionFactory
Namespace: PostSharp.Patterns.Contracts
Assembly: PostSharp.Patterns.Common.dll
Syntax
public abstract class ContractExceptionFactory
Remarks

To change the exceptions that contracts throw, derive a class from ContractExceptionFactory and override the CreateException(ContractExceptionInfo) method. Return an exception for the cases that your factory handles, and call the base implementation for the others, which invokes the next factory in the chain. At application startup, assign an instance of your factory to ExceptionFactory, and pass the previous value of this property to the constructor.

The default factory creates ArgumentException, ArgumentNullException, ArgumentOutOfRangeException and PostconditionFailedException, with a message obtained from LocalizedTextProvider. When no factory of the chain handles the requested exception type, the base implementation throws an InvalidOperationException.

Custom contracts can create their exceptions through ExceptionFactory, so that the same customizations apply to them.

Constructors

Name Description
ContractExceptionFactory(ContractExceptionFactory)

Initializes a new instance of the ContractExceptionFactory class.

Methods

Name Description
CreateException(ContractExceptionInfo)

Creates the exception based on the contents of ContractExceptionInfo.

See Also