Skip to content

Commit

Permalink
chore: wrap GetFromRuntimeInformation() in try-catch (#1554)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Mar 26, 2022
1 parent e3ca414 commit 1cdde37
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Sentry/PlatformAbstractions/RuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,20 @@ internal static void SetNetCoreVersion(Runtime runtime)

internal static Runtime? GetFromRuntimeInformation()
{
// Preferred API: netstandard2.0
// https://github.com/dotnet/corefx/blob/master/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs
// https://github.com/mono/mono/blob/90b49aa3aebb594e0409341f9dca63b74f9df52e/mcs/class/corlib/System.Runtime.InteropServices.RuntimeInformation/RuntimeInformation.cs
// e.g: .NET Framework 4.7.2633.0, .NET Native, WebAssembly
var frameworkDescription = RuntimeInformation.FrameworkDescription;
string frameworkDescription;
try
{
// Preferred API: netstandard2.0
// https://github.com/dotnet/corefx/blob/master/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs
// https://github.com/mono/mono/blob/90b49aa3aebb594e0409341f9dca63b74f9df52e/mcs/class/corlib/System.Runtime.InteropServices.RuntimeInformation/RuntimeInformation.cs
// e.g: .NET Framework 4.7.2633.0, .NET Native, WebAssembly
// Note: this throws on some Unity IL2CPP versions
frameworkDescription = RuntimeInformation.FrameworkDescription;
}
catch
{
return null;
}

return Parse(frameworkDescription);
}
Expand Down

0 comments on commit 1cdde37

Please sign in to comment.