Table of Contents

Class NearbyConnectException

Namespace
Plugin.Maui.NearbyConnectivity
Assembly
Plugin.Maui.NearbyConnectivity.dll

The exception that is thrown when a handshake ends without producing a connection.

public sealed class NearbyConnectException : NearbyException, ISerializable
Inheritance
NearbyConnectException
Implements
Inherited Members

Remarks

One exception for every way a connect can fail, with Reason carrying which. An elapsed offer window raises the same exception to the initiator and to the acceptor, because the deadline is declared once and shared.

Branch on Reason, not on the exception type:

try
{
    var connection = await device.ConnectAsync(cancellationToken);
}
catch (NearbyConnectException ex) when (ex.Reason is NearbyConnectFailure.TimedOut)
{
    Status = $"{device.Presence.DisplayName} did not answer.";
}

Canceling the CancellationToken passed to the call raises OperationCanceledException instead. A withdrawal by this app is not a handshake failure.

Constructors

NearbyConnectException(NearbyConnectFailure, string)

Initializes a new instance of the NearbyConnectException class.

public NearbyConnectException(NearbyConnectFailure reason, string message)

Parameters

reason NearbyConnectFailure

Why the handshake ended without a connection.

message string

The error message that explains the reason for the exception.

NearbyConnectException(NearbyConnectFailure, string, Exception)

Initializes a new instance of the NearbyConnectException class.

public NearbyConnectException(NearbyConnectFailure reason, string message, Exception innerException)

Parameters

reason NearbyConnectFailure

Why the handshake ended without a connection.

message string

The error message that explains the reason for the exception.

innerException Exception

The exception that is the cause of the current exception.

Properties

Reason

Gets why the handshake ended without a connection.

public NearbyConnectFailure Reason { get; }

Property Value

NearbyConnectFailure

TimedOut when the offer window elapsed, DeviceUnknown when the device is no longer known to the session, or Failed when the handshake ended without a connection for any other reason, including a decline, which the platforms do not report consistently enough to report on its own.