Added try catch to the default constructor to show the details of an error if something goes wrong.

This commit is contained in:
2019-12-01 00:11:13 +00:00
parent 25d88b0609
commit 1185770a94
2 changed files with 41 additions and 9 deletions
@@ -220,7 +220,7 @@ namespace Meade.net.Telescope.UnitTests
{ {
ConnectTelescope(); ConnectTelescope();
string parameters = $"Count"; string parameters = "Count";
var result = _telescope.Action("site", parameters); var result = _telescope.Action("site", parameters);
Assert.That(result, Is.EqualTo("4")); Assert.That(result, Is.EqualTo("4"));
+40 -8
View File
@@ -5,6 +5,8 @@ using System.Collections;
using System.Globalization; using System.Globalization;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using ASCOM.Astrometry; using ASCOM.Astrometry;
using ASCOM.Astrometry.AstroUtils; using ASCOM.Astrometry.AstroUtils;
using ASCOM.Astrometry.NOVAS; using ASCOM.Astrometry.NOVAS;
@@ -79,15 +81,45 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
public Telescope() public Telescope()
{ {
//todo move this out to IOC try
var util = new Util(); //Initialise util object {
_utilities = util; //todo move this out to IOC
_utilitiesExtra = util; //Initialise util object var util = new Util(); //Initialise util object
_astroUtilities = new AstroUtils(); // Initialise astro utilities object _utilities = util;
_sharedResourcesWrapper = new SharedResourcesWrapper(); _utilitiesExtra = util; //Initialise util object
_astroMaths = new AstroMaths.AstroMaths(); _astroUtilities = new AstroUtils(); // Initialise astro utilities object
_sharedResourcesWrapper = new SharedResourcesWrapper();
_astroMaths = new AstroMaths.AstroMaths();
Initialise(); Initialise();
}
catch (Exception e)
{
StringBuilder sb = new StringBuilder();
var currentException = e;
while (currentException != null)
{
AppendException(sb, currentException);
currentException = currentException.InnerException;
if (currentException != null)
sb.AppendLine("-----");
}
MessageBox.Show(sb.ToString());
throw;
}
}
private void AppendException(StringBuilder sb, Exception currentException)
{
sb.AppendLine(currentException.Message);
sb.AppendLine();
sb.AppendLine(currentException.StackTrace);
sb.AppendLine();
} }
public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths) public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths)