Link to home
Start Free TrialLog in
Avatar of trevor1940
trevor1940

asked on

c#: Error Trapping

Hi,

I'm looking at ways to convert MGRS coordinates to Decimal  Latitude, Longitude  I've come across CoordinateSharp  the Developer Guide makes use of tryParse but dosn't seem say how to trap the errors nor dose the dotnetfiddle example

I also note the output is Degree minute seconds not digital

The Developer Guide Suggests "c.FormatOptions.CoordinateFormatType = CoordinateFormatType.Degree_Decimal_Minutes;"


However this Errors

		string mgrs = "16R CV 05774 44722";
		Coordinate c;
		if(Coordinate.TryParse("16R CV 05774 44722", out c))
		{
			c.FormatOptions.CoordinateFormatType = CoordinateFormatType.Degree_Decimal_Minutes;

			Console.WriteLine(c);
		}

Open in new window


So how do I rewrite the above trapping errors and output to  Decimal  Latitude, Longitude variables?
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trevor1940
trevor1940

ASKER

OK so this works

		Coordinate c;
		if(Coordinate.TryParse("crap 16R CV 05774 44722", out c))
		{
			string Lat = c.Latitude.DecimalDegree.ToString();
			string Long = c.Longitude.DecimalDegree.ToString();
			Console.WriteLine(Lat + ", " + Long);
		}
		else{
				Console.WriteLine("Error!");
		}

Open in new window


However it doesn't give any indication of what the error is In this case it's badly formatted MGRS, I've seen examples out of range where user has typed the wrong values correctly
At a short glance at the parsers, they internally only use the TryParse pattern and don't bubble up any message where it failed. So in the current state, it seems, that you cannot get that information.

But as it is on GitHub, you can add this feature if you like.
Thanx I find it quite odd not being able tell errors