Skip to content

Throw Exceptions In Unexpected Locations

Michael Damatov edited this page Dec 15, 2024 · 7 revisions

Shows a warning when exceptions are thrown in unexpected locations.

Unexpected Location Allowed exceptions (incl. all derivatives)
property getters InvalidOperationException, NotSupportedException
indexer getters ArgumentException, InvalidOperationException, KeyNotFoundException, NotSupportedException
event accessors ArgumentException, InvalidOperationException, NotSupportedException
static constructors none
finalizers none
equality operators (== and !=) none
implicit cast operators none
object.Equals method overrides none
object.GetHashCode method overrides none
object.ToString method overrides none
IEquatable<T>.Equals method implementations none
IEqualityComparer.Equals method implementations none
IEqualityComparer.GetHashCode method implementations ArgumentException
IEqualityComparer<T>.Equals method implementations none
IEqualityComparer<T>.GetHashCode method implementations ArgumentException
IDisposable.Dispose method implementations none
IAsyncDisposable.DisposeAsync method implementations none
Dispose(false) code paths none
finally blocks none
exception filter expressions none

Note

No warning is shown when the UnreachableException is thrown.

Current Limitations

  • Only direct throw expressions and statements are evaluated. Exceptions thrown by called methods are not evaluated.
  • The Dispose(false) code path is checked regardless of whether it's called by the finalizer.

💡 The analyzer can be deactivated in the ReSharper Options dialog.

References

Clone this wiki locally