Provide more exception details when PlatformDetection.ToVersion fails (dotnet/corefx...
authorStephen Toub <stoub@microsoft.com>
Tue, 11 Jun 2019 20:00:42 +0000 (13:00 -0700)
committerGitHub <noreply@github.com>
Tue, 11 Jun 2019 20:00:42 +0000 (13:00 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/49b6ade10a35e44573da6e851bc09133d5922c0a

src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs

index 541b417..bbcf9f5 100644 (file)
@@ -157,12 +157,19 @@ namespace System
 
         static Version ToVersion(string versionString)
         {
-            if (versionString.IndexOf('.') != -1)
-                return new Version(versionString);
+            try
+            {
+                if (versionString.IndexOf('.') != -1)
+                    return new Version(versionString);
 
-            // minor version is required by Version
-            // let's default it to 0
-            return new Version(int.Parse(versionString), 0);
+                // minor version is required by Version
+                // let's default it to 0
+                return new Version(int.Parse(versionString), 0);
+            }
+            catch (Exception exc)
+            {
+                throw new FormatException($"Failed to parse version string: '{versionString}'", exc);
+            }
         }
 
         private static (string name, Version version) GetDistroInfo() =>