mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user