Skip to content

Uncatchable Exceptions

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

Exceptions that should never be caught

The analyzer discourages catching of some .NET Framework exceptions.

The exception cannot be caught.

  • System.Security.HostProtectionException

The exception indicates a bug that can be avoided.

  • System.AccessViolationException
  • System.AppDomainUnloadedException
  • System.ArgumentException
  • System.ArgumentNullException
  • System.ArgumentOutOfRangeException
  • System.ArrayTypeMismatchException
  • System.Collections.Generic.KeyNotFoundException
  • System.ComponentModel.InvalidEnumArgumentException
  • System.Configuration.SettingsPropertyIsReadOnlyException
  • System.Configuration.SettingsPropertyNotFoundException
  • System.Configuration.SettingsPropertyWrongTypeException
  • System.Data.DeletedRowInaccessibleException
  • System.Data.EvaluateException
  • System.Data.InRowChangingEventException
  • System.Data.InvalidConstraintException
  • System.Data.InvalidExpressionException
  • System.Data.MissingPrimaryKeyException
  • System.Data.NoNullAllowedException
  • System.Data.ReadOnlyException
  • System.Data.RowNotInTableException
  • System.Data.StrongTypingException
  • System.Data.SyntaxErrorException
  • System.Data.VersionNotFoundException
  • System.Diagnostics.Contracts.ContractException
  • System.Diagnostics.UnreachableException
  • System.DuplicateWaitObjectException
  • System.FieldAccessException
  • System.IndexOutOfRangeException
  • System.InvalidCastException
  • System.MemberAccessException
  • System.MethodAccessException
  • System.MissingFieldException
  • System.MissingMemberException
  • System.MissingMethodException
  • System.MulticastNotSupportedException
  • System.NotImplementedException
  • System.NotSupportedException
  • System.NullReferenceException
  • System.ObjectDisposedException
  • System.PlatformNotSupportedException
  • System.RankException
  • System.Runtime.AmbiguousImplementationException
  • System.Runtime.CompilerServices.SwitchExpressionException
  • System.Runtime.InteropServices.InvalidComObjectException
  • System.Runtime.InteropServices.InvalidOleVariantTypeException
  • System.Runtime.InteropServices.MarshalDirectiveException
  • System.Runtime.InteropServices.SafeArrayRankMismatchException
  • System.Threading.ThreadAbortException
  • System.Windows.Automation.ElementNotEnabledException
  • System.Windows.ResourceReferenceKeyNotFoundException

The exception represents an unrecoverable state.

  • System.OutOfMemoryException
  • System.StackOverflowException

The exception should not be used in any way.

  • Microsoft.JScript.BreakOutOfFinally
  • Microsoft.JScript.CmdLineException
  • Microsoft.JScript.ContinueOutOfFinally
  • Microsoft.JScript.EndOfFile
  • Microsoft.JScript.JScriptException
  • Microsoft.JScript.NoContextException
  • Microsoft.JScript.ParserException
  • Microsoft.JScript.ReturnOutOfFinally
  • Microsoft.VisualBasic.CompilerServices.IncompleteInitialization
  • Microsoft.VisualBasic.CompilerServices.InternalErrorException
  • System.Net.Mail.SmtpFailedRecipientsException

Note: Not all .NET APIs are made consistently. For example, the Process.GetProcessById method throws an ArgumentException, which cannot be avoided in any way. In such a case the warning should just be suppressed.

Note: Please feel free to raise an issue if you mean that some exceptions are missing or were incorrectly put in the list.

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