Skip to content

Unthrowable Exceptions

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

Exceptions that should never be thrown

The analyzer discourages throwing of some .NET Framework exceptions.

A more specific exception should be used.

  • System.ApplicationException
  • System.ComponentModel.WarningException
  • System.Data.EntityException
  • System.Data.SqlTypes.SqlTypeException
  • System.Data.TypedDataSetGeneratorException
  • System.DirectoryServices.AccountManagement.PrincipalException
  • System.DirectoryServices.Protocols.DirectoryException
  • System.Exception
  • System.IdentityModel.RequestException
  • System.IdentityModel.Services.FederationException
  • System.Management.Instrumentation.InstrumentationBaseException
  • System.Net.Http.HttpRequestException
  • System.Runtime.DurableInstancing.InstancePersistenceException
  • System.SystemException

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

The exception should only be thrown by the .NET Configuration API.

  • System.Configuration.ConfigurationErrorsException
  • System.Configuration.ConfigurationException
  • System.Configuration.Provider.ProviderException
  • System.Configuration.SettingsPropertyIsReadOnlyException
  • System.Configuration.SettingsPropertyNotFoundException
  • System.Configuration.SettingsPropertyWrongTypeException

The exception should only be thrown by the ADO API.

  • System.Data.DataException
  • System.Data.Odbc.OdbcException
  • System.Data.OleDb.OleDbException
  • System.Data.OracleClient.OracleException
  • System.Data.SqlClient.SqlException

The exception should only be thrown by the ClickOnce API.

  • System.Deployment.Application.CompatibleFrameworkMissingException
  • System.Deployment.Application.DependentPlatformMissingException
  • System.Deployment.Application.DeploymentDownloadException
  • System.Deployment.Application.DeploymentException
  • System.Deployment.Application.InvalidDeploymentException
  • System.Deployment.Application.SupportedRuntimeMissingException
  • System.Deployment.Application.TrustNotGrantedException

The exception should only be thrown by the CLR.

  • Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
  • Microsoft.CSharp.RuntimeBinder.RuntimeBinderInternalCompilerException
  • System.AccessViolationException
  • System.AppDomainUnloadedException
  • System.ArrayTypeMismatchException
  • System.BadImageFormatException
  • System.CannotUnloadAppDomainException
  • System.ContextMarshalException
  • System.DataMisalignedException
  • System.DllNotFoundException
  • System.EntryPointNotFoundException
  • System.ExecutionEngineException
  • System.FieldAccessException
  • System.IndexOutOfRangeException
  • System.InsufficientExecutionStackException
  • System.InsufficientMemoryException
  • System.InvalidProgramException
  • System.IO.FileLoadException
  • System.MemberAccessException
  • System.MethodAccessException
  • System.MissingFieldException
  • System.MissingMemberException
  • System.MissingMethodException
  • System.MulticastNotSupportedException
  • System.NullReferenceException
  • System.OutOfMemoryException
  • System.RankException
  • System.Resources.MissingManifestResourceException
  • System.Resources.MissingSatelliteAssemblyException
  • System.Runtime.AmbiguousImplementationException
  • System.Runtime.CompilerServices.RuntimeWrappedException
  • System.Runtime.CompilerServices.SwitchExpressionException
  • System.Runtime.InteropServices.COMException
  • System.Runtime.InteropServices.ExternalException
  • System.Runtime.InteropServices.InvalidComObjectException
  • System.Runtime.InteropServices.InvalidOleVariantTypeException
  • System.Runtime.InteropServices.MarshalDirectiveException
  • System.Runtime.InteropServices.SafeArrayRankMismatchException
  • System.Runtime.InteropServices.SEHException
  • System.Security.HostProtectionException
  • System.StackOverflowException
  • System.Threading.BarrierPostPhaseException
  • System.Threading.ThreadAbortException
  • System.Threading.ThreadInterruptedException
  • System.Threading.ThreadStartException
  • System.Threading.ThreadStateException
  • System.TypeAccessException
  • System.TypeInitializationException
  • System.TypeLoadException
  • System.TypeUnloadedException

The exception should only be thrown by the compression engine.

  • System.IO.Compression.ZLibException

The exception should only be thrown by the MEF API.

  • System.ComponentModel.Composition.ChangeRejectedException
  • System.ComponentModel.Composition.CompositionContractMismatchException
  • System.ComponentModel.Composition.CompositionException
  • System.ComponentModel.Composition.ImportCardinalityMismatchException
  • System.ComponentModel.Composition.Primitives.ComposablePartException

The exception should only be thrown by the Message Queue API.

  • System.Messaging.MessageQueueException

The exception should only be thrown by the MSBuild engine.

  • Microsoft.Build.BuildEngine.InternalLoggerException
  • Microsoft.Build.BuildEngine.RemoteErrorException
  • Microsoft.Build.Exceptions.InternalLoggerException

The exception should only be thrown by the Reflection API.

  • System.Reflection.AmbiguousMatchException
  • System.Reflection.ReflectionTypeLoadException
  • System.Reflection.TargetException
  • System.Reflection.TargetInvocationException
  • System.Reflection.TargetParameterCountException

The exception should only be thrown by the Remoting API.

  • System.Runtime.Remoting.MetadataServices.SUDSGeneratorException
  • System.Runtime.Remoting.MetadataServices.SUDSParserException

The exception should only be thrown by the SQL Server API.

  • Microsoft.SqlServer.Server.InvalidUdtException

The exception should only be thrown by the TPL API.

  • System.AggregateException

The exception should only be thrown by the WCF API.

  • System.IdentityModel.Selectors.CardSpaceException

The exception should only be thrown by the WPF API.

  • System.Windows.Markup.XamlParseException
  • System.Windows.Media.Animation.AnimationException

The exception uses non-generic collections.

  • System.ComponentModel.Design.ExceptionCollection

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.

References

Clone this wiki locally