From cfcd9dbcb97383cc4a92437676f0bd0bdd9343c3 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 11 Jun 2019 13:00:42 -0700 Subject: [PATCH] Provide more exception details when PlatformDetection.ToVersion fails (dotnet/corefx#38463) Commit migrated from https://github.com/dotnet/corefx/commit/49b6ade10a35e44573da6e851bc09133d5922c0a --- .../src/System/PlatformDetection.Unix.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs index 541b417..bbcf9f5 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs +++ b/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs @@ -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() => -- 2.7.4