Replace use of throw GetExceptionForHR with ThrowExceptionForHR (#11640)

`System.Runtime.InteropServices.Marshall.GetExceptionForHR` may not return an exception. Instead of `throw GetExceptionForHR` we can use `ThrowExceptionForHR`.

Fix warnings `CS8597:Thrown value may be null.`
This commit is contained in:
xtqqczze
2020-01-31 10:13:12 +05:00
committed by GitHub
parent 3d90f5ef2b
commit c4e144b13e
3 changed files with 7 additions and 17 deletions
@@ -3088,7 +3088,7 @@ namespace Microsoft.PowerShell.Commands
}
else
{
throw Marshal.GetExceptionForHR(Security.NativeMethods.NTE_NOT_SUPPORTED);
Marshal.ThrowExceptionForHR(Security.NativeMethods.NTE_NOT_SUPPORTED);
}
}
@@ -133,17 +133,14 @@ namespace Microsoft.CodeAnalysis
if (hr != ERROR_INSUFFICIENT_BUFFER)
{
throw Marshal.GetExceptionForHR(hr);
Marshal.ThrowExceptionForHR(hr);
}
byte[] data = new byte[(int)characterCountIncludingTerminator * 2];
fixed (byte* p = data)
{
hr = nameObject.GetDisplayName(p, ref characterCountIncludingTerminator, displayFlags);
if (hr != 0)
{
throw Marshal.GetExceptionForHR(hr);
}
Marshal.ThrowExceptionForHR(hr);
return Marshal.PtrToStringUni((IntPtr)p, (int)characterCountIncludingTerminator - 1);
}
@@ -162,17 +159,14 @@ namespace Microsoft.CodeAnalysis
if (hr != ERROR_INSUFFICIENT_BUFFER)
{
throw Marshal.GetExceptionForHR(hr);
Marshal.ThrowExceptionForHR(hr);
}
byte[] data = new byte[(int)size];
fixed (byte* p = data)
{
hr = nameObject.GetProperty(propertyId, p, ref size);
if (hr != 0)
{
throw Marshal.GetExceptionForHR(hr);
}
Marshal.ThrowExceptionForHR(hr);
}
return data;
@@ -210,10 +204,7 @@ namespace Microsoft.CodeAnalysis
uint result;
uint size = sizeof(uint);
int hr = nameObject.GetProperty(propertyId, &result, ref size);
if (hr != 0)
{
throw Marshal.GetExceptionForHR(hr);
}
Marshal.ThrowExceptionForHR(hr);
if (size == 0)
{
@@ -900,8 +900,7 @@ namespace System.Management.Automation.Internal
if (newfilter.Contains("=") || newfilter.Contains("&"))
{
throw Marshal.GetExceptionForHR(
Security.NativeMethods.E_INVALID_DATA);
Marshal.ThrowExceptionForHR(Security.NativeMethods.E_INVALID_DATA);
}
newfilter = name + "=" + newfilter;