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
messagestringThe 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
messagestringThe error message that explains the reason for the exception.
innerExceptionExceptionThe 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
operationstringThe name of the operation that timed out.
durationTimeSpanThe 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
operationstringThe name of the operation that timed out.
durationTimeSpanThe duration that elapsed before the timeout.
operationCanceledExceptionOperationCanceledExceptionThe 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
operationstringThe name of the operation that timed out.
durationTimeSpanThe duration that elapsed before the timeout.
timeoutTimeSpanThe configured timeout limit.
Properties
Duration
Gets the duration that elapsed before the timeout.
public TimeSpan? Duration { get; }
Property Value
Operation
Gets the name of the operation that timed out.
public string? Operation { get; }
Property Value
Timeout
Gets the configured timeout limit.
public TimeSpan? Timeout { get; }
Property Value
Methods
DatabaseQuery(string, TimeSpan)
Creates an OperationTimeoutException for a database query timeout.
public static OperationTimeoutException DatabaseQuery(string queryName, TimeSpan elapsed)
Parameters
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
Returns
- OperationTimeoutException
A new OperationTimeoutException instance.
FromCancellation(string, TimeSpan, OperationCanceledException)
Creates an OperationTimeoutException from an OperationCanceledException.
public static OperationTimeoutException FromCancellation(string operation, TimeSpan elapsed, OperationCanceledException ex)
Parameters
operationstringThe name of the operation that timed out.
elapsedTimeSpanThe time that elapsed.
exOperationCanceledExceptionThe 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.