# AR51Exception

<Badge tone="type">class · sealed</Badge> <Badge>thread-safe</Badge>

```csharp
namespace AR51.Net;

public sealed class AR51Exception : Exception
```

**Implements:** `Exception`

Thrown when a call to the AR 51 system fails. `ErrorCode` says why.

Cancellation is reported as `OperationCanceledException` and use after dispose as `ObjectDisposedException`, as usual in .NET.

:::tip[How-to]
This page is **reference** (facts only). For a walkthrough with a complete sample, see the [Connecting guide](/docs/csharp-api/connecting/).
:::

<Example>

```csharp
try
{
    await ar51.Calibration.StartCalibrationAsync();
}
catch (AR51Exception exception) when (exception.ErrorCode == AR51ErrorCode.Rejected)
{
    Console.WriteLine($"Refused by the server: {exception.Message}");   // e.g. a calibration is already running
}
```

</Example>

## Properties

<div className="apiPropTable apiTable">

| Property | Type | Access | Description |
|---|---|---|---|
| `ErrorCode` | [`AR51ErrorCode`](#ar51errorcode) | `get` | What went wrong. |

</div>

## Method summary

<div className="apiTable">

| Method | Returns | |
|---|---|---|
| [`Constructor`](#constructor) | — | <Badge>constructor</Badge> |

</div>

→ Full descriptions in [Method details](#method-details) below.

## Method details

### Constructor

<ApiBody kind="method">

```csharp
public AR51Exception(AR51ErrorCode errorCode, string message, Exception? innerException = null);
```

Creates the exception.

<Params>
<Param name="errorCode" type="AR51ErrorCode" typeHref="#ar51errorcode">What went wrong.</Param>
<Param name="message" type="string">A description for logs and developers.</Param>
<Param name="innerException" type="Exception?">The underlying error, if any. Optional.</Param>
</Params>

</ApiBody>

## Related types

Small types used by this class, documented here.

### AR51ErrorCode

<Badge tone="type">enum</Badge>

```csharp
public enum AR51ErrorCode
```

What went wrong in a `AR51Exception`.

<div className="apiTable">

| Value | Meaning |
|---|---|
| `Unknown = 0` | An unexpected error. See the inner exception. |
| `ServiceUnavailable = 1` | The server, or the service needed for the call, is not reachable right now. |
| `ConnectionLost = 2` | The connection dropped while the call was running. |
| `Timeout = 3` | The server did not answer in time. |
| `ServerError = 4` | The server failed while handling the request. Retrying is unlikely to help until the server is fixed or restarted. |
| `Rejected = 5` | The server understood the request and refused it, for example a calibration is already running or a camera does not exist. `Exception.Message` carries the server's reason; the request may succeed later. |

</div>

## See also

- [Connecting guide](/docs/csharp-api/connecting/) — walkthrough with a complete, compiled sample
- [Class index](/docs/sdk-api/csharp-api/classes/) — every AR51.Net type
- [Data conventions, threading and errors](/docs/csharp-api/conventions/)
