From aaced855d8e0395d7d756f7611379141b1087a78 Mon Sep 17 00:00:00 2001 From: ORelio Date: Mon, 23 Mar 2015 13:57:31 +0100 Subject: [PATCH] Catch exceptions for bots for onTextReceived Avoid crashing due to bots not properly processing text --- MinecraftClient/McTcpClient.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 781b61d6..8716ffe3 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -305,8 +305,21 @@ namespace MinecraftClient public void OnTextReceived(string text) { ConsoleIO.WriteLineFormatted(text, false); - foreach (ChatBot bot in new List(bots)) - bot.GetText(text); + for (int i = 0; i < bots.Count; i++) + { + try + { + bots[i].GetText(text); + } + catch (Exception e) + { + if (!(e is ThreadAbortException)) + { + ConsoleIO.WriteLineFormatted("§8GetText: Got error from " + bots[i].ToString() + ": " + e.ToString()); + } + else throw; //ThreadAbortException should not be caught + } + } } /// @@ -357,7 +370,7 @@ namespace MinecraftClient { if (!(e is ThreadAbortException)) { - ConsoleIO.WriteLineFormatted("§8Got error from " + bots[i].ToString() + ": " + e.ToString()); + ConsoleIO.WriteLineFormatted("§8Update: Got error from " + bots[i].ToString() + ": " + e.ToString()); } else throw; //ThreadAbortException should not be caught }