Skip to content

Throw Exceptions In Unexpected Locations

Michael Damatov edited this page Jan 17, 2024 · 6 revisions

Shows a warning when exceptions are thrown in unexpected locations.

Unexpected Location Exceptions expected (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

Note

No warning is shown when the UnreachableException is thrown.

Current Limitations

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

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

References