Enable MA0012 and MA0014 and fix noncompliance
"Do not raise reserved exception type" and "Do not raise System.ApplicationException type" now mostly compliant with https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/using-standard-exception-types
This commit is contained in:
parent
a2fef59fe1
commit
8ac4dabaf7
|
@ -147,13 +147,13 @@
|
|||
<Rule Id="MA0011" Action="Hidden" />
|
||||
|
||||
<!-- Do not raise reserved exception type -->
|
||||
<Rule Id="MA0012" Action="Hidden" />
|
||||
<Rule Id="MA0012" Action="Error" />
|
||||
|
||||
<!-- Types should not extend System.ApplicationException -->
|
||||
<Rule Id="MA0013" Action="Error" />
|
||||
|
||||
<!-- Do not raise System.ApplicationException type -->
|
||||
<Rule Id="MA0014" Action="Hidden" />
|
||||
<Rule Id="MA0014" Action="Error" />
|
||||
|
||||
<!-- Specify the parameter name in ArgumentException -->
|
||||
<Rule Id="MA0015" Action="Hidden" />
|
||||
|
|
|
@ -297,14 +297,16 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
{
|
||||
readonly get
|
||||
{
|
||||
if (rowIndex is < 0 or > 3) throw new ArgumentOutOfRangeException(paramName: nameof(rowIndex), rowIndex, message: "index out of range");
|
||||
if (columnIndex is < 0 or > 3) throw new ArgumentOutOfRangeException(paramName: nameof(columnIndex), columnIndex, message: "index out of range");
|
||||
var i = rowIndex * 4 + columnIndex;
|
||||
if (i < 0 || 15 < i) throw new IndexOutOfRangeException($"no such element m[{rowIndex}, {columnIndex}] of {nameof(Matrix4)}");
|
||||
fixed (Matrix4* p = &this) return ((float*) p)[i];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowIndex is < 0 or > 3) throw new ArgumentOutOfRangeException(paramName: nameof(rowIndex), rowIndex, message: "index out of range");
|
||||
if (columnIndex is < 0 or > 3) throw new ArgumentOutOfRangeException(paramName: nameof(columnIndex), columnIndex, message: "index out of range");
|
||||
var i = rowIndex * 4 + columnIndex;
|
||||
if (i < 0 || 15 < i) throw new IndexOutOfRangeException($"no such element m[{rowIndex}, {columnIndex}] of {nameof(Matrix4)}");
|
||||
fixed (Matrix4* p = &this) ((float*) p)[i] = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ namespace BizHawk.Client.Common
|
|||
[return: LuaArbitraryStringParam]
|
||||
public string HttpTest()
|
||||
{
|
||||
if (APIs.Comm.HTTP == null) throw new NullReferenceException(); // to match previous behaviour
|
||||
_ = APIs.Comm.HTTP!; // to match previous behaviour
|
||||
return UnFixString(APIs.Comm.HttpTest());
|
||||
}
|
||||
|
||||
|
|
|
@ -286,8 +286,7 @@ namespace BizHawk.Client.Common
|
|||
/// <returns></returns>
|
||||
public StateInformation GetState(int index)
|
||||
{
|
||||
if ((uint)index >= (uint)Count)
|
||||
throw new IndexOutOfRangeException();
|
||||
if ((uint) index >= (uint) Count) throw new ArgumentOutOfRangeException(paramName: nameof(index), index, message: "index out of range");
|
||||
return new StateInformation(this, (index + _firstStateIndex) & STATEMASK);
|
||||
}
|
||||
|
||||
|
@ -297,8 +296,10 @@ namespace BizHawk.Client.Common
|
|||
/// <param name="index"></param>
|
||||
public void InvalidateEnd(int index)
|
||||
{
|
||||
if ((uint)index > (uint)Count)
|
||||
throw new IndexOutOfRangeException();
|
||||
if ((uint) index > (uint) Count) // intentionally allows index == Count (e.g. clearing an empty buffer)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(paramName: nameof(index), index, message: "index out of range");
|
||||
}
|
||||
_nextStateIndex = (index + _firstStateIndex) & STATEMASK;
|
||||
//Util.DebugWriteLine($"Size: {Size >> 20}MiB, Used: {Used >> 20}MiB, States: {Count}");
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var valueObjs = lti.Values;
|
||||
if (keyObjs.Count != valueObjs.Count)
|
||||
{
|
||||
throw new IndexOutOfRangeException("each value must be paired with one key, they differ in number");
|
||||
throw new ArgumentException(message: "each value must be paired with one key, they differ in number", paramName: nameof(lti));
|
||||
}
|
||||
|
||||
var values = new object[keyObjs.Count];
|
||||
|
|
|
@ -68,9 +68,7 @@ namespace BizHawk.Common
|
|||
return true;
|
||||
}
|
||||
|
||||
private static readonly MethodInfo ArrayEqualsGeneric
|
||||
= typeof(DeepEquality).GetMethod(nameof(ArrayEquals), BindingFlags.NonPublic | BindingFlags.Static)
|
||||
?? throw new NullReferenceException();
|
||||
private static readonly MethodInfo ArrayEqualsGeneric = typeof(DeepEquality).GetMethod(nameof(ArrayEquals), BindingFlags.NonPublic | BindingFlags.Static)!;
|
||||
|
||||
/// <summary>test if two objects <paramref name="o1"/> and <paramref name="o2"/> are equal, field-by-field (with deep inspection of each field)</summary>
|
||||
/// <exception cref="InvalidOperationException"><paramref name="o1"/> is an array with rank > 1 or is a non-zero-indexed array</exception>
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace BizHawk.Common
|
|||
_extractor = DearchivalMethod.Construct(path);
|
||||
try
|
||||
{
|
||||
_archiveItems = _extractor.Scan() ?? throw new NullReferenceException();
|
||||
_archiveItems = _extractor.Scan()!;
|
||||
IsArchive = true;
|
||||
}
|
||||
catch
|
||||
|
|
|
@ -66,8 +66,10 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
case LibSpeexDSP.RESAMPLER_ERR.SUCCESS:
|
||||
return;
|
||||
#pragma warning disable MA0012 // this will crash the .NET host, as it should
|
||||
case LibSpeexDSP.RESAMPLER_ERR.ALLOC_FAILED:
|
||||
throw new InsufficientMemoryException($"{nameof(LibSpeexDSP)}: Alloc failed");
|
||||
#pragma warning restore MA0012
|
||||
case LibSpeexDSP.RESAMPLER_ERR.BAD_STATE:
|
||||
throw new Exception($"{nameof(LibSpeexDSP)}: Bad state");
|
||||
case LibSpeexDSP.RESAMPLER_ERR.INVALID_ARG:
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
{
|
||||
if (erom.Length != 8192)
|
||||
{
|
||||
throw new ApplicationException("EROM file is wrong size - expected 8192 bytes");
|
||||
throw new ArgumentException(message: "EROM file is wrong size - expected 8192 bytes", paramName: nameof(erom));
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
|
@ -103,7 +103,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
{
|
||||
if (grom.Length != 2048)
|
||||
{
|
||||
throw new ApplicationException("GROM file is wrong size - expected 2048 bytes");
|
||||
throw new ArgumentException(message: "GROM file is wrong size - expected 2048 bytes", paramName: nameof(grom));
|
||||
}
|
||||
|
||||
GraphicsRom = grom;
|
||||
|
|
|
@ -78,14 +78,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
_sram.Data = s.sram;
|
||||
|
||||
// special combined ram memory domain
|
||||
const int SIZE_COMBINED = (256 + 32) * 1024;
|
||||
_cwram.Peek =
|
||||
addr =>
|
||||
{
|
||||
if (addr < 0 || addr >= (256 + 32) * 1024)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
if (addr is < 0 or >= SIZE_COMBINED) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "invalid address");
|
||||
if (addr >= 256 * 1024)
|
||||
{
|
||||
return PeekWRAM(s.iwram, addr & 32767);
|
||||
|
@ -96,11 +93,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
_cwram.Poke =
|
||||
(addr, val) =>
|
||||
{
|
||||
if (addr < 0 || addr >= (256 + 32) * 1024)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
if (addr is < 0 or >= SIZE_COMBINED) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "invalid address");
|
||||
if (addr >= 256 * 1024)
|
||||
{
|
||||
PokeWRAM(s.iwram, addr & 32767, val);
|
||||
|
|
Loading…
Reference in New Issue