From 03f2022f2fb0dd4f0a2a4e533c5deae5302fbdac Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 3 Sep 2020 21:04:28 +0100 Subject: [PATCH] Refactored the error message --- .../SharedResourcesUnitTests.cs | 4 ++-- Meade.net/SharedResources.cs | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 1b95ab2..025bfb5 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -375,11 +375,11 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.Transmit("#:GG#")).Callback(() => { serialPortReturn = ""; }); _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn); - var result = Assert.Throws(() => + var result = Assert.Throws(() => { SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); }); - Assert.That(result.Message, Is.EqualTo("Input string was not in a correct format.")); + Assert.That(result.Message, Is.EqualTo("Unable to decode response from the telescope, This is likely a hardware serial communications error.")); _traceLoggerMock.Verify( x => x.LogIssue("Connect", "Unable to decode response from the telescope, This is likely a hardware serial communications error."), Times.Once); } diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 0087300..b0fed12 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.Windows.Forms; using ASCOM.Meade.net.Wrapper; @@ -309,16 +310,13 @@ namespace ASCOM.Meade.net //Returns: sHH# or sHH.H# //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the //sHH# form is returned, otherwise the longer form is returned. - try - { - double.Parse(utcOffSet); - } - catch (Exception) - { - traceLogger.LogIssue("Connect", "Unable to decode response from the telescope, This is likely a hardware serial communications error."); - throw; - } - + double utcOffsetHours; + if (!double.TryParse(utcOffSet, out utcOffsetHours)) + { + var message = "Unable to decode response from the telescope, This is likely a hardware serial communications error."; + traceLogger.LogIssue("Connect", message); + throw new Exception(message); + } } catch (Exception) {