Table of Contents

Class OperationTimeoutException

Namespace
Excalibur.Dispatch.Exceptions
Assembly
Excalibur.Dispatch.dll

Exception thrown when an operation exceeds its allowed time limit.

public sealed class OperationTimeoutException : DispatchException, ISerializable
Inheritance
OperationTimeoutException
Implements
Inherited Members
Extension Methods

Examples

var cts = new CancellationTokenSource(timeout);
try
{
    await ProcessAsync(cts.Token);
}
catch (OperationCanceledException) when (cts.IsCancellationRequested)
{
    throw new OperationTimeoutException("ProcessAsync", timeout);
}

Remarks

This exception indicates that an operation took longer than the configured timeout and was terminated or aborted. It maps to HTTP status code 408 (Request Timeout).

Use this exception when:

  • A database query exceeds its timeout
  • An external service call takes too long
  • A long-running operation exceeds its time limit
  • A lock acquisition times out

Constructors

OperationTimeoutException()

Initializes a new instance of the OperationTimeoutException class.

public OperationTimeoutException()

OperationTimeoutException(string)

Initializes a new instance of the OperationTimeoutException class with a specified error message.

public OperationTimeoutException(string message)

Parameters

message string

The error message that explains the reason for the exception.

OperationTimeoutException(string, Exception?)

Initializes a new instance of the OperationTimeoutException class with a message and inner exception.

public OperationTimeoutException(string message, Exception? innerException)

Parameters

message string

The error message that explains the reason for the exception.

innerException Exception

The exception that is the cause of the current exception.

OperationTimeoutException(string, TimeSpan)

Initializes a new instance of the OperationTimeoutException class with operation information.

public OperationTimeoutException(string operation, TimeSpan duration)

Parameters

operation string

The name of the operation that timed out.

duration TimeSpan

The duration that elapsed before the timeout.

OperationTimeoutException(string, TimeSpan, OperationCanceledException)

Initializes a new instance of the OperationTimeoutException class with the original cancellation exception.

public OperationTimeoutException(string operation, TimeSpan duration, OperationCanceledException operationCanceledException)

Parameters

operation string

The name of the operation that timed out.

duration TimeSpan

The duration that elapsed before the timeout.

operationCanceledException OperationCanceledException

The original cancellation exception.

OperationTimeoutException(string, TimeSpan, TimeSpan)

Initializes a new instance of the OperationTimeoutException class with operation and timeout information.

public OperationTimeoutException(string operation, TimeSpan duration, TimeSpan timeout)

Parameters

operation string

The name of the operation that timed out.

duration TimeSpan

The duration that elapsed before the timeout.

timeout TimeSpan

The configured timeout limit.

Properties

Duration

Gets the duration that elapsed before the timeout.

public TimeSpan? Duration { get; }

Property Value

TimeSpan?

The elapsed duration, or null if not specified.

Operation

Gets the name of the operation that timed out.

public string? Operation { get; }

Property Value

string

The operation name, or null if not specified.

Timeout

Gets the configured timeout limit.

public TimeSpan? Timeout { get; }

Property Value

TimeSpan?

The timeout limit, or null if not specified.

Methods

DatabaseQuery(string, TimeSpan)

Creates an OperationTimeoutException for a database query timeout.

public static OperationTimeoutException DatabaseQuery(string queryName, TimeSpan elapsed)

Parameters

queryName string

The name or description of the query.

elapsed TimeSpan

The time that elapsed.

Returns

OperationTimeoutException

A new OperationTimeoutException instance.

ExternalService(string, TimeSpan)

Creates an OperationTimeoutException for an external service call timeout.

public static OperationTimeoutException ExternalService(string serviceName, TimeSpan elapsed)

Parameters

serviceName string

The name of the external service.

elapsed TimeSpan

The time that elapsed.

Returns

OperationTimeoutException

A new OperationTimeoutException instance.

FromCancellation(string, TimeSpan, OperationCanceledException)

public static OperationTimeoutException FromCancellation(string operation, TimeSpan elapsed, OperationCanceledException ex)

Parameters

operation string

The name of the operation that timed out.

elapsed TimeSpan

The time that elapsed.

ex OperationCanceledException

The original cancellation exception.

Returns

OperationTimeoutException

A new OperationTimeoutException instance.

GetProblemDetailsExtensions()

Gets additional extension data to include in problem details.

protected override IDictionary<string, object?>? GetProblemDetailsExtensions()

Returns

IDictionary<string, object>

A dictionary of extension data to include in the problem details response, or null if no extensions should be added.

Remarks

Derived types can override this method to add type-specific data to the problem details response. For example, a ValidationException might include a dictionary of field-level validation errors.

The returned dictionary keys will be added to the problem details Extensions collection.