Table of Contents

Class CosmosException

Namespace
Microsoft.Azure.Cosmos
Assembly
Microsoft.Azure.Cosmos.Client.dll

The Cosmos Client exception

public class CosmosException : Exception, ISerializable
Inheritance
CosmosException
Implements
Inherited Members
Extension Methods

Constructors

CosmosException(string, HttpStatusCode, int, string, double)

Create a CosmosException

public CosmosException(string message, HttpStatusCode statusCode, int subStatusCode, string activityId, double requestCharge)

Parameters

message string

The message associated with the exception.

statusCode HttpStatusCode

The HttpStatusCode associated with the exception.

subStatusCode int

A sub status code associated with the exception.

activityId string

An ActivityId associated with the operation that generated the exception.

requestCharge double

A request charge associated with the operation that generated the exception.

Properties

ActivityId

Gets the activity ID for the request from the Azure Cosmos DB service.

public virtual string ActivityId { get; }

Property Value

string

The activity ID for the request.

Diagnostics

Gets the diagnostics for the request

public virtual CosmosDiagnostics Diagnostics { get; }

Property Value

CosmosDiagnostics

Headers

Gets the response headers

public virtual Headers Headers { get; }

Property Value

Headers

Message

public override string Message { get; }

Property Value

string

RequestCharge

Gets the request charge for this request from the Azure Cosmos DB service.

public virtual double RequestCharge { get; }

Property Value

double

The request charge measured in request units.

ResponseBody

The body of the cosmos response message as a string

public virtual string ResponseBody { get; }

Property Value

string

RetryAfter

Gets the retry after time. This tells how long a request should wait before doing a retry.

public virtual TimeSpan? RetryAfter { get; }

Property Value

TimeSpan?

StackTrace

public override string StackTrace { get; }

Property Value

string

StatusCode

Gets the request completion status code from the Azure Cosmos DB service.

public virtual HttpStatusCode StatusCode { get; }

Property Value

HttpStatusCode

The request completion status code

SubStatusCode

Gets the request completion sub status code from the Azure Cosmos DB service.

public virtual int SubStatusCode { get; }

Property Value

int

The request completion status code

Methods

ToString()

Create a custom string with all the relevant exception information

public override string ToString()

Returns

string

A string representation of the exception.

TryGetHeader(string, out string)

Try to get a header from the cosmos response message

public virtual bool TryGetHeader(string headerName, out string value)

Parameters

headerName string
value string

Returns

bool

A value indicating if the header was read.