From e021d5a56b479d516469673a2fa334a98fe3098c Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Fri, 28 Jul 2017 22:18:39 +0200 Subject: [PATCH] Handle exceptions whicha re thrown while processing application messages. --- MQTTnet.Core/Client/MqttClient.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/MQTTnet.Core/Client/MqttClient.cs b/MQTTnet.Core/Client/MqttClient.cs index df3c61fac..3cec8d86d 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/MQTTnet.Core/Client/MqttClient.cs @@ -238,7 +238,15 @@ private void FireApplicationMessageReceivedEvent(MqttPublishPacket publishPacket } var applicationMessage = publishPacket.ToApplicationMessage(); - ApplicationMessageReceived?.Invoke(this, new MqttApplicationMessageReceivedEventArgs(applicationMessage)); + + try + { + ApplicationMessageReceived?.Invoke(this, new MqttApplicationMessageReceivedEventArgs(applicationMessage)); + } + catch (Exception exception) + { + MqttTrace.Error(nameof(MqttClient), exception, "Unhandled exception while handling application message."); + } } private Task ProcessReceivedPublishPacket(MqttPublishPacket publishPacket)