Cheat Sheet - .NET Framework Exceptions

Here's a list of Exceptions that can be found in the assemblies which are most commonly used in ASP.NET development.  Ideally, you should be as specific as possible when catching or throwing Exceptions. The more specific you are, the less work the CLR has to do in locating the appropriate catch block, and the more informative your error messages are, which should help speed up identifying the source of any problems.

A forthcoming article will explain how I generated this list using gacutil.exe and Reflection, and show you how you can customise the code to read other assemblies that you might use more often.

UPDATE: The article is now available: Using gacutil.exe and Reflection to generate the Exceptions Cheat Sheet

mscorlib
AbandonedMutexException The exception that is thrown when one thread acquires a System.Threading.Mutex object that another thread has abandoned by exiting without releasing it.
AccessViolationException The exception that is thrown when there is an attempt to read or write protected memory.
AmbiguousMatchException The exception that is thrown when binding to a member results in more than one member matching the binding criteria. This class cannot be inherited.
AppDomainUnloadedException The exception that is thrown when an attempt is made to access an unloaded application domain.
ApplicationException The exception that is thrown when a non-fatal application error occurs.
ArgumentException The exception that is thrown when one of the arguments provided to a method is not valid.
ArgumentNullException The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.
ArgumentOutOfRangeException The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method.
ArithmeticException The exception that is thrown for errors in an arithmetic, casting, or conversion operation.
ArrayTypeMismatchException The exception that is thrown when an attempt is made to store an element of the wrong type within an array.
ASSERT
BadImageFormatException The exception that is thrown when the file image of a DLL or an executable program is invalid.
CannotUnloadAppDomainException The exception that is thrown when an attempt to unload an application domain fails.
COMException The exception that is thrown when an unrecognized HRESULT is returned from a COM method call.
ContextMarshalException The exception that is thrown when an attempt to marshal an object across a context boundary fails.
CryptographicException The exception that is thrown when an error occurs during a cryptographic operation.
CryptographicUnexpectedOperationException The exception that is thrown when an unexpected operation occurs during a cryptographic operation.
CustomAttributeFormatException The exception that is thrown when the binary format of a custom attribute is invalid.
DataMisalignedException The exception that is thrown when a unit of data is read from or written to an address that is not a multiple of the data size. This class cannot be inherited.
DecoderFallbackException The exception that is thrown when a decoder fallback operation fails. This class cannot be inherited.
DirectoryNotFoundException The exception that is thrown when part of a file or directory cannot be found.
DivideByZeroException The exception that is thrown when there is an attempt to divide an integral or decimal value by zero.
DllNotFoundException The exception that is thrown when a DLL specified in a DLL import cannot be found.
DriveNotFoundException The exception that is thrown when trying to access a drive or share that is not available.
DuplicateWaitObjectException The exception that is thrown when an object appears more than once in an array of synchronization objects.
EncoderFallbackException The exception that is thrown when an encoder fallback operation fails. This class cannot be inherited.
EndOfStreamException The exception that is thrown when reading is attempted past the end of a stream.
EntryPointNotFoundException The exception that is thrown when an attempt to load a class fails due to the absence of an entry method.
ExecutionEngineException The exception that is thrown when there is an internal error in the execution engine of the common language runtime. This class cannot be inherited.
ExternalException The base exception type for all COM interop exceptions and structured exception handling (SEH) exceptions.
FieldAccessException The exception that is thrown when there is an invalid attempt to access a private or protected field inside a class.
FileLoadException The exception that is thrown when a managed assembly is found but cannot be loaded.
FileNotFoundException The exception that is thrown when an attempt to access a file that does not exist on disk fails.
FormatException The exception that is thrown when the format of an argument does not meet the parameter specifications of the invoked method.
HostProtectionException The exception that is thrown when a denied host resource is detected.
IdentityNotMappedException Represents an exception for a principal whose identity could not be mapped to a known identity.
IndexOutOfRangeException The exception that is thrown when an attempt is made to access an element of an array with an index that is outside the bounds of the array. This class cannot be inherited.
InsufficientMemoryException The exception that is thrown when a check for sufficient available memory fails. This class cannot be inherited.
InvalidCastException The exception that is thrown for invalid casting or explicit conversion.
InvalidComObjectException The exception thrown when an invalid COM object is used.
InvalidFilterCriteriaException The exception that is thrown in System.Type.FindMembers(System.Reflection.MemberTypes, System.Reflection.BindingFlags, System.Reflection.MemberFilter, System.Object) when the filter criteria is not valid for the type of filter you are using.
InvalidOleVariantTypeException The exception thrown by the marshaler when it encounters an argument of a variant type that can not be marshaled to managed code.
InvalidOperationException The exception that is thrown when a method call is invalid for the object's current state.
InvalidProgramException The exception that is thrown when a program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in the compiler that generated the program.
IOException The exception that is thrown when an I/O error occurs.
IsolatedStorageException The exception that is thrown when an operation in isolated storage fails.
KeyNotFoundException The exception that is thrown when the key specified for accessing an element in a collection does not match any key in the collection.
MarshalDirectiveException The exception that is thrown by the marshaler when it encounters a System.Runtime.InteropServices.MarshalAsAttribute it does not support.
MemberAccessException The exception that is thrown when an attempt to access a class member fails.
MetadataException
MethodAccessException The exception that is thrown when there is an invalid attempt to access a private or protected method inside a class.
MissingFieldException The exception that is thrown when there is an attempt to dynamically access a field that does not exist.
MissingManifestResourceException The exception thrown if the main assembly does not contain the resources for the neutral culture, and they are required because of a missing appropriate satellite assembly.
MissingMemberException The exception that is thrown when there is an attempt to dynamically access a class member that does not exist.
MissingMethodException The exception that is thrown when there is an attempt to dynamically access a method that does not exist.
MissingSatelliteAssemblyException The exception that is thrown when the satellite assembly for the resources of the neutral culture is missing.
MulticastNotSupportedException The exception that is thrown when there is an attempt to combine two delegates based on the System.Delegate type instead of the System.MulticastDelegate type. This class cannot be inherited.
NotFiniteNumberException The exception that is thrown when a floating-point value is positive infinity, negative infinity, or Not-a-Number (NaN).
NotImplementedException The exception that is thrown when a requested method or operation is not implemented.
NotSupportedException The exception that is thrown when an invoked method is not supported, or when there is an attempt to read, seek, or write to a stream that does not support the invoked functionality.
NullReferenceException The exception that is thrown when there is an attempt to dereference a null object reference.
ObjectDisposedException The exception that is thrown when an operation is performed on a disposed object.
OperationCanceledException The exception that is thrown in a thread upon cancellation of an operation that the thread was executing.
OutOfMemoryException The exception that is thrown when there is not enough memory to continue the execution of a program.
OverflowException The exception that is thrown when an arithmetic, casting, or conversion operation in a checked context results in an overflow.
PathTooLongException The exception that is thrown when a pathname or filename is longer than the system-defined maximum length.
PlatformNotSupportedException The exception that is thrown when a feature does not run on a particular platform.
PolicyException The exception that is thrown when policy forbids code to run.
PrivilegeNotHeldException The exception that is thrown when a method in the System.Security.AccessControl namespace attempts to enable a privilege that it does not have.
RankException The exception that is thrown when an array with the wrong number of dimensions is passed to a method.
ReflectionTypeLoadException The exception that is thrown by the System.Reflection.Module.GetTypes method if any of the classes in a module cannot be loaded. This class cannot be inherited.
RemotingException The exception that is thrown when something has gone wrong during remoting.
RemotingTimeoutException The exception that is thrown when the server or the client cannot be reached for a previously specified period of time.
RuntimeWrappedException Wraps an exception that does not derive from the System.Exception class. This class cannot be inherited.
SafeArrayRankMismatchException The exception thrown when the rank of an incoming SAFEARRAY does not match the rank specified in the managed signature.
SafeArrayTypeMismatchException The exception thrown when the type of the incoming SAFEARRAY does not match the type specified in the managed signature.
SecurityException The exception that is thrown when a security error is detected.
SEHException Represents Structured Exception Handler (SEH) errors.
SerializationException The exception thrown when an error occurs during serialization or deserialization.
ServerException The exception that is thrown to communicate errors to the client when the client connects to non-.NET Framework applications that cannot throw exceptions.
StackOverflowException The exception that is thrown when the execution stack overflows because it contains too many nested method calls. This class cannot be inherited.
SynchronizationLockException The exception that is thrown when a method requires the caller to own the lock on a given Monitor, and the method is invoked by a caller that does not own that lock.
SystemException Defines the base class for predefined exceptions in the System namespace.
TargetException Represents the exception that is thrown when an attempt is made to invoke an invalid target.
TargetInvocationException The exception that is thrown by methods invoked through reflection. This class cannot be inherited.
TargetParameterCountException The exception that is thrown when the number of parameters for an invocation does not match the number expected. This class cannot be inherited.
ThreadAbortException The exception that is thrown when a call is made to the System.Threading.Thread.Abort(System.Object) method. This class cannot be inherited.
ThreadInterruptedException The exception that is thrown when a System.Threading.Thread is interrupted while it is in a waiting state.
ThreadStartException The exception that is thrown when a failure occurs in a managed thread after the underlying operating system thread has been started, but before the thread is ready to execute user code.
ThreadStateException The exception that is thrown when a System.Threading.Thread is in an invalid System.Threading.Thread.ThreadState for the method call.
TimeoutException The exception that is thrown when the time allotted for a process or operation has expired.
TypeInitializationException The exception that is thrown as a wrapper around the exception thrown by the class initializer. This class cannot be inherited.
TypeLoadException The exception that is thrown when type-loading failures occur.
TypeUnloadedException The exception that is thrown when there is an attempt to access an unloaded class.
UnauthorizedAccessException The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.
VerificationException The exception that is thrown when the security policy requires code to be type safe and the verification process is unable to verify that the code is type safe.
WaitHandleCannotBeOpenedException The exception that is thrown when an attempt is made to open a system mutex or semaphore that does not exist.
XmlSyntaxException The exception that is thrown when there is a syntax error in XML parsing. This class cannot be inherited.
System
AuthenticationException The exception that is thrown when authentication fails for an authentication stream.
CheckoutException The exception that is thrown when an attempt to check out a file that is checked into a source code management program is canceled or fails.
ConfigurationException The exception that is thrown when a configuration system error has occurred.
CookieException The exception that is thrown when an error is made adding a System.Net.Cookie to a System.Net.CookieContainer.
HttpListenerException The exception that is thrown when an error occurs processing an HTTP request.
InternalBufferOverflowException The exception thrown when the internal buffer overflows.
InternalException
InvalidAsynchronousStateException Thrown when a thread on which an operation should execute no longer exists or has no message loop.
InvalidCredentialException The exception that is thrown when authentication fails for an authentication stream and cannot be retried.
InvalidDataException The exception that is thrown when a data stream is in an invalid format.
InvalidEnumArgumentException The exception thrown when using invalid arguments that are enumerators.
LicenseException Represents the exception thrown when a component cannot be granted a license.
NetworkInformationException The exception that is thrown when an error occurs while retrieving network information.
PingException The exception that is thrown when a System.Net.NetworkInformation.Ping.Send or System.Net.NetworkInformation.Ping.SendAsync method calls a method that throws an exception.
ProtocolViolationException The exception that is thrown when an error is made while using a network protocol.
SemaphoreFullException The exception that is thrown when the System.Threading.Semaphore.Release method is called on a semaphore whose count is already at the maximum.
SettingsPropertyIsReadOnlyException Provides an exception for read-only System.Configuration.SettingsProperty objects.
SettingsPropertyNotFoundException Provides an exception for System.Configuration.SettingsProperty objects that are not found.
SettingsPropertyWrongTypeException Provides an exception that is thrown when an invalid type is used with a System.Configuration.SettingsProperty object.
SmtpException Represents the exception that is thrown when the System.Net.Mail.SmtpClient is not able to complete a System.Net.Mail.SmtpClient.Send or System.Net.Mail.SmtpClient.SendAsync operation.
SmtpFailedRecipientException Represents the exception that is thrown when the System.Net.Mail.SmtpClient is not able to complete a System.Net.Mail.SmtpClient.Send or System.Net.Mail.SmtpClient.SendAsync operation to a particular recipient.
SmtpFailedRecipientsException The exception that is thrown when e-mail is sent using an System.Net.Mail.SmtpClient and cannot be delivered to all recipients.
SocketException The exception that is thrown when a socket error occurs.
UriFormatException The exception that is thrown when an invalid Uniform Resource Identifier (URI) is detected.
WarningException Specifies an exception that is handled as a warning instead of an error.
WebException The exception that is thrown when an error occurs while accessing the network through a pluggable protocol.
Win32Exception Throws an exception for a Win32 error code.
System.Configuration
ConfigurationErrorsException The current value is not one of the System.Web.Configuration.PagesSection.EnableSessionState values.
ProviderException The exception that is thrown when a configuration provider error has occurred. This exception class is also used by providers to throw exceptions when internal errors occur within the provider that do not map to other pre-existing exception classes.
System.Core
AssertionException
AssumptionException
EventLogException Represents the base class for all the exceptions that are thrown when an error occurs while reading event log related information.
EventLogInvalidDataException Represents the exception thrown when an event provider publishes invalid data in an event.
EventLogNotFoundException Represents the exception that is thrown when a requested event log (usually specified by the name of the event log or the path to the event log file) does not exist.
EventLogProviderDisabledException Represents the exception that is thrown when a specified event provider name references a disabled event provider. A disabled event provider cannot publish events.
EventLogReadingException Represents an exception that is thrown when an error occurred while reading, querying, or subscribing to the events in an event log.
InstanceNotFoundException The exception thrown to indicate that no instances are returned by a provider.
InstrumentationBaseException Represents the base provider-related exception.
InstrumentationException Represents a provider-related exception.
InvalidTimeZoneException The exception that is thrown when time zone information is invalid.
InvariantException
LockRecursionException The exception that is thrown when recursive entry into a lock is not compatible with the recursion policy for the lock.
PostconditionException
PreconditionException
SystemCore_EnumerableDebugViewEmptyException
TimeZoneNotFoundException The exception that is thrown when a time zone cannot be found.
System.Data
ConstraintException Represents the exception that is thrown when attempting an action that violates a constraint.
DataException Represents the exception that is thrown when errors are generated using ADO.NET components.
DBConcurrencyException The exception that is thrown by the System.Data.Common.DataAdapter during an insert, update, or delete operation if the number of rows affected equals zero.
DbException The base class for all exceptions thrown on behalf of the data source.
DeletedRowInaccessibleException Represents the exception that is thrown when an action is tried on a System.Data.DataRow that has been deleted.
DuplicateNameException Represents the exception that is thrown when a duplicate database object name is encountered during an add operation in a System.Data.DataSet -related object.
EvaluateException Represents the exception that is thrown when the System.Data.DataColumn.Expression property of a System.Data.DataColumn cannot be evaluated.
InRowChangingEventException Represents the exception that is thrown when you call the System.Data.DataRow.EndEdit method within the System.Data.DataTable.RowChanging event.
InvalidConstraintException Represents the exception that is thrown when incorrectly trying to create or access a relation.
InvalidExpressionException Represents the exception that is thrown when you try to add a System.Data.DataColumn that contains an invalid System.Data.DataColumn.Expression to a System.Data.DataColumnCollection.
InvalidUdtException Thrown when SQL Server or the ADO.NET System.Data.SqlClient provider detects an invalid user-defined type (UDT).
MissingPrimaryKeyException Represents the exception that is thrown when you try to access a row in a table that has no primary key.
ModuleLoadException
ModuleLoadExceptionHandlerException
NoNullAllowedException Represents the exception that is thrown when you try to insert a null value into a column where System.Data.DataColumn.AllowDBNull is set to false.
OdbcException The exception that is generated when a warning or error is returned by an ODBC data source. This class cannot be inherited.
OleDbException The exception that is thrown when the underlying provider returns a warning or error for an OLE DB data source. This class cannot be inherited.
OperationAbortedException This exception is thrown when an ongoing operation is aborted by the user.
ReadOnlyException Represents the exception that is thrown when you try to change the value of a read-only column.
RowNotInTableException Represents the exception that is thrown when you try to perform an operation on a System.Data.DataRow that is not in a System.Data.DataTable.
SqlAlreadyFilledException The System.Data.SqlTypes.SqlAlreadyFilledException class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
SqlException The exception that is thrown when SQL Server returns a warning or error. This class cannot be inherited.
SqlNotFilledException The System.Data.SqlTypes.SqlNotFilledException class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
SqlNullValueException The exception that is thrown when the Value property of a System.Data.SqlTypes structure is set to null.
SqlTruncateException The exception that is thrown when you set a value into a System.Data.SqlTypes structure would truncate that value.
SqlTypeException The base exception class for the System.Data.SqlTypes.
StrongTypingException The exception that is thrown by a strongly typed System.Data.DataSet when the user accesses a DBNull value.
SyntaxErrorException Represents the exception that is thrown when the System.Data.DataColumn.Expression property of a System.Data.DataColumn contains a syntax error.
TypedDataSetGeneratorException The exception that is thrown when a name conflict occurs while generating a strongly typed System.Data.DataSet.
VersionNotFoundException Represents the exception that is thrown when you try to return a version of a System.Data.DataRow that has been deleted.
System.Data.Entity
EntityCommandCompilationException Represents errors that occur during command compilation; when a command tree could not be produced to represent the command text.
EntityCommandExecutionException Represents errors that occur when the underlying storage provider could not execute the specified command. This exception usually wraps a provider-specific exception.
EntityException Represents Entity Framework-related errors that occur in the EntityClient namespace. The EntityException is the base class for all Entity Framework exceptions thrown by the EntityClient.
EntitySqlException Represents errors that occur when parsing Entity SQL command text. This exception is thrown when syntactic or semantic rules are violated.
InternalMappingException
InvalidCommandTreeException The exception that is thrown to indicate that a command tree is invalid.
MappingException The exception that is thrown when mapping related service requests fail.
MetadataException The exception that is thrown when metadata related service requests fails.
ObjectNotFoundException The exception that is thrown when an object is not present.
OptimisticConcurrencyException The exception that is thrown when an optimistic concurrency violation occurs.
ProviderIncompatibleException The exception that is thrown when the underlying data provider is incompatible with the Entity Framework.
UpdateException The exception that is thrown when modifications to object instances cannot be persisted to the data store.
System.Data.Linq
ChangeConflictException Thrown when an update fails because database values have been updated since the client last read them.
DuplicateKeyException Thrown when an attempt is made to add an object to the identity cache by using a key that is already being used.
ForeignKeyReferenceAlreadyHasValueException Represents errors that occur when an attempt is made to change a foreign key when the entity is already loaded.
System.Data.Services
DataServiceException Represents an instance of the System.Data.Services.DataServiceException class with a specified message that describes the error.
System.Web
DatabaseNotEnabledForNotificationException The exception that is thrown when a SQL Server database is not enabled to support dependencies associated with the System.Web.Caching.SqlCacheDependency class. This class cannot be inherited.
HostingEnvironmentException
HttpCompileException The exception that is thrown when a compiler error occurs.
HttpException Describes an exception that occurred during the processing of HTTP requests.
HttpParseException The exception that is thrown when a parse error occurs.
HttpRequestValidationException The exception that is thrown when a potentially malicious input string is received from the client as part of the request data. This class cannot be inherited.
HttpUnhandledException The exception that is thrown when a generic exception occurs.
MembershipCreateUserException The exception that is thrown when a user is not successfully created by a membership provider.
MembershipPasswordException The exception that is thrown when a password cannot be retrieved from the password store.
SqlExecutionException Defines a class for SQL execution exceptions in the System.Web.Management namespace.
TableNotEnabledForNotificationException The exception that is thrown when a System.Web.Caching.SqlCacheDependency class is used against a database table that is not enabled for change notifications.
ViewStateException Represents the exception that is thrown when the view state cannot be loaded or validated. This class cannot be inherited.
System.Web.Services
InvalidContentTypeException
InvalidDocumentContentsException
SoapException Represents the exception that is thrown when an XML Web service method is called over SOAP and an exception occurs.
SoapHeaderException The SOAP representation of a server error.
System.Xml
UpaException
XmlException Returns detailed information about the last exception.
XmlSchemaException Returns detailed information about the schema exception.
XmlSchemaInferenceException Returns information about errors encountered by the System.Xml.Schema.XmlSchemaInference class while inferring a schema from an XML document.
XmlSchemaValidationException Represents the exception thrown when XML Schema Definition Language (XSD) schema validation errors and warnings are encountered in an XML document being validated.
XPathException Provides the exception thrown when an error occurs while processing an XPath expression.
XsltCompileException The exception that is thrown by the Load method when an error is found in the XSLT style sheet.
XsltException The exception that is thrown when an error occurs while processing an XSLT transformation.

 

Shout it

Date Posted: Sunday, February 7, 2010 5:19 PM
Last Updated: Wednesday, February 10, 2010 7:31 AM
Posted by: Mikesdotnetting
Total Views to date: 27253

6 Comments

Monday, February 8, 2010 9:53 AM - Hassan mehmood

Great list.. I can use it for many purposes. thanks..

Thursday, June 14, 2012 12:07 PM - kshitiz

good one ! thanks

Wednesday, February 6, 2013 9:59 AM - Afzaal Ahmad Zeeshan

Pretty much helpfull. Surely this page needs a +Bookmark by everyone!

Thanks alot sir :)

Monday, April 1, 2013 8:12 AM - Asit

Great list! I bookmarked this page reference. Thanks! :)

Sunday, December 22, 2013 12:05 PM - Afzaal Ahmad Zeeshan

Aaaa, am I wrong or this sheet is missing System.Mail.SmtpExcepton?

I think, this should be added to the System exceptions..

Sunday, December 22, 2013 2:19 PM - Mike

@Afzaal

I'm afraid you are wrong. The exception you are looking for is in the System.Net.Mail namespace, not System.

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpexception(v=vs.110).aspx
Add your comment

If you have any comments to make about this article, please use this form to do so. Make sure that your comment relates specifically to the article above. More general comments can be posted through the form on the Contact page.

Please note, all comments are moderated, and some may not be published. The kind of things that will ensure your comment is deleted without ever seeing the light of day are as follows:

  • Not relevant to the article
  • Gratuitous links to your own site or product
  • Anything abusive or libellous
  • Spam
  • Anything in a language I don't understand including gibberish.

I do not pass email addresses on to spammers, so a valid one will assist me in responding to you personally if required.