我有一个使用Microsoft.Azure.Devices.Client.DeviceClient侦听来自Azure IoT中心的消息的Xamarin应用程序。偶尔我会得到我无法捕捉并处理的错误。一个这样的例外是:Azure IoTHub抛出异常我无法捕捉
Microsoft.Azure.Devices.Client.Exceptions.UnauthorizedException
此异常只是一个例外,我正在和一个我可以可靠地通过更改系统时间重建的一个例子。其他IoTHubExceptions零星且很难重新创建,因此需要尝试捕获异常。
任何人都可以告诉我如何可以捕获这些基于物联网集线器的错误?代码是:
try
{
await _deviceClientInbound.OpenAsync();
// execution never gets passed this line and the exception is eventually thrown, having reached this point
Message receivedMessage = await _deviceClientInbound.ReceiveAsync();
if (receivedMessage == null) continue;
await _deviceClientInbound.CompleteAsync(receivedMessage);
}
catch (Exception e)
{
// Exception is never caught in here ...
// How can I catch the IoTHubException based exceptions
}
就是这段代码被声明为返回'任务功能'或'任务'?你是否也确定它是从这些电话中抛出的? –
juunas
是的,该方法的签名是“私人异步任务StartReceiverAsync()”,而我不能100%确定这是造成问题的这个电话。这是我做任何IoTHub相关的唯一的地方,只有当执行达到此代码时才会出现问题。 – Slicc