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"));
+32
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;
@@ -78,6 +80,8 @@ namespace ASCOM.Meade.net
/// Must be public for COM registration. /// Must be public for COM registration.
/// </summary> /// </summary>
public Telescope() public Telescope()
{
try
{ {
//todo move this out to IOC //todo move this out to IOC
var util = new Util(); //Initialise util object var util = new Util(); //Initialise util object
@@ -89,6 +93,34 @@ namespace ASCOM.Meade.net
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)
{ {