List of Exceptions in C#

Saad Aslam Jan 30, 2023
  1. System Exceptions in C#
  2. System.Data Exceptions in C#
  3. System.IO Exceptions in C#
  4. System.Net Exceptions in C#
  5. System.Net.Mail Exceptions in C#
  6. System.Net.NetworkInformation Exceptions in C#
  7. System.Resources Exceptions in C#
List of Exceptions in C#

This article is about the exceptions that come with pre-defined C#’s Exception class.

The System Exception class is a pre-defined Exception class in the C# programming language that is available in programming. Select an exception that might arise from your code and insert it into the appropriate catch block.

This chapter will provide a comprehensive list of all system exception classes. You may use this exception to write code that is both errors free and very resilient.

System Exceptions in C#

  1. AccessViolationException - The exception is generated whenever an attempt to read from or write to protected memory.
  2. AppDomainUnloadedException - An exception is generated whenever an attempt to access an application domain has not yet been loaded.
  3. ApplicationException - The exception will be thrown if an application error is not fatal.
  4. ArgumentException - The error message is shown to the user when one of the parameters supplied to a method is invalid.
  5. ArgumentNullException - The exception is generated whenever a procedure that does not accept a null reference as a valid parameter receives a reference to a null value (referred to as Nothing in Visual Basic).
  6. ArgumentOutOfRangeException - When an argument’s value falls outside the range of permissible values established by the method that has been called, the exception is thrown.
  7. ArithmeticException - The exception is thrown if a computation, casting, or conversion action results in an error.
  8. ArrayTypeMismatchException - When an attempt is made to save an element of the incorrect type inside an array, the exception is issued.
  9. BadImageFormatException - When a dynamic link library (DLL) or an executable program has a corrupted file image, the exception is raised.
  10. CannotUnloadAppDomainException - If a failed effort is made to unload an application domain, the exception is thrown.
  11. ContextMarshalException - An exception is thrown if an object cannot be marshaled over a context border.
  12. DataMisalignedException - If a unit of data is read from or written to an address that isn’t a multiple of the data size, an exception is thrown. When the data size is not a multiple of the address, an exception is thrown.
  13. DivideByZeroException - The exception is produced whenever an attempt is made to divide a decimal number or an integral value by zero.
  14. DllNotFoundException - The exception is if a dynamic link library (DLL) specified in a DLL import cannot be located.
  15. DuplicateWaitObjectException - An exception is thrown if an array contains numerous instances of the same object.
  16. EntryPointNotFoundException - The exception is produced if a failed attempt to load a class because the lack of an entry method causes the class to be loaded.
  17. ExecutionEngineException - The exception is raised whenever the common language runtime’s execution engine encounters an error local to the system.
  18. FieldAccessException - The exception is generated whenever an invalid attempt is made to access a private or protected field that is included inside a class.
  19. FormatException - This occurs when the structure of an argument does not match the parameters supplied by the method call.
  20. IndexOutOfRangeException - The exception is issued if an attempt is made to access an element of an array with an index beyond the array’s limits. This class cannot have its inheritance passed down to other classes.
  21. InsufficientMemoryException - The exception is triggered if a check for adequate, accessible memory returns an incorrect result. This class cannot have its inheritance passed down to other classes.
  22. InvalidCastException - The exception will be triggered if the casting procedure is faulty or an explicit conversion is done.
  23. InvalidOperationException - The exception is raised whenever a method call cannot be carried out because of the present state of the object.
  24. InvalidProgramException - If a program has incorrect Microsoft Intermediate Language (MSIL) or metadata, the exception is raised. In most cases, this is an indication that there is a problem with the compiler that was used to build the program.
  25. MemberAccessException - The exception is raised whenever an unsuccessful attempt is made to access a class member.
  26. MethodAccessException - The exception occurs whenever an invalid attempt is made to access a private or protected method inside a class.
  27. MissingFieldException - The exception is generated whenever someone attempts to dynamically access a field that does not exist in the database.
  28. MissingMemberException - The exception is issued if there is an attempt to dynamically access a class member that does not exist.
  29. MissingMethodException - The exception is if someone attempts to dynamically access a method that does not exist in the program.
  30. MulticastNotSupportedException - The exception is raised if a combination of two delegates based on the type rather than the type is attempted.
  31. NotFiniteNumberException - Any value that is either positive or negative infinity, or does not exist, will cause an exception to be raised (NaN).
  32. NotImplementedException - The exception is raised if a requested method or action cannot be carried out because it is not implemented.
  33. NotSupportedException - The exception is raised when a method that has been called does not support the functionality that has been invoked or when an attempt is made to read, seek, or write to a stream that doesn’t support the functionality that has been invoked.
  34. NullReferenceException - The error is raised if a de-reference operation is attempted on an object reference that has been previously configured to null.
  35. ObjectDisposedException - The exception is generated if an operation is carried out on an object that has been disposed of.
  36. OperationCanceledException - The exception is raised in a thread if the thread is stopped from carrying out an activity previously carried out.
  37. OutOfMemoryException - The exception is raised if there is insufficient memory to continue the execution of a program. Also known as the memory exception.
  38. OverflowException - The exception is raised if an action involving casting, conversion, or arithmetic results in an overflow when performed in a checked context.
  39. PlatformNotSupportedException - The exception is raised if a feature is attempted to be executed on a platform for which it is not supported.
  40. RankException - The exception is raised if a method receives a parameter with an array with an incorrect number of dimensions.
  41. StackOverflowException - The exception is raised if the execution stack overflows due to having an excessive number of nested method calls.
  42. SystemException - This function specifies the base class for any exceptions established inside the namespace.
  43. TimeoutException - The exception is issued if the amount of time permitted for a procedure or action has run out.
  44. TypeInitializationException - The exception thrown around is the exception thrown by the class initializer when it is wrapped up and thrown.
  45. TypeLoadException - The exception is raised if there is a problem with the type loading.
  46. TypeUnloadedException - The exception is generated if a class that has not yet been loaded is attempted to be accessed.
  47. UnauthorizedAccessException - The exception is raised if the operating system refuses to provide access because of a problem with input or output (I/O) or a particular kind of security fault.

System.Data Exceptions in C#

  1. ConstraintException - This object represents the exception that is raised when an action is attempted that would violate a constraint.
  2. DataException - The exception is delivered if an error is produced by utilizing ADO.NET components.
  3. DBConcurrencyException - The exception is issued when doing an insert, update, or delete action if the number of rows impacted is equal to zero.
  4. DeletedRowInaccessibleException - It is used to represent the exception that is raised if an action is attempted to be performed on a that has been removed.
  5. DuplicateNameException - Represents the exception produced if an add operation is performed on a linked object and a database object name is found to be duplicated in use.
  6. EvaluateException - A representation of the exception is raised when a property evaluation cannot occur.
  7. InRowChangingEventException - Represents the error message shown when the method is called from inside the event.
  8. InvalidConstraintException - The exception is produced if an attempt is made to access or construct a relation improperly is represented by this class.
  9. InvalidExpressionException - This object represents the error produced when an attempt is made to add a DataColumn to a DataColumnCollection when the DataColumn includes an incorrect Expression.
  10. MissingPrimaryKeyException - When a row in a table that doesn’t have a primary key is tried to be accessed, this exception is thrown.
  11. NoNullAllowedException - The exception will be issued if you attempt to insert a null value into a column with the property set to false where it should not be.
  12. OperationAbortedException - This exception is produced if a user cancels a currently running action.
  13. ReadOnlyException - The exception is produced whenever an attempt is made to modify the value of a column that is restricted to read-only access.
  14. RowNotInTableException - The exception is raised when you attempt to execute an action on a that is not included in a. Represents the error message that is shown when the exception is thrown.
  15. StrongTypingException - The exception is generated by a highly typed system whenever a user attempts to access a DBNull variable.
  16. SyntaxErrorException - The exception is thrown when the property of a has a syntax mistake is represented by this object.
  17. TypedDataSetGeneratorException - If a name conflict arises when a strongly typed is generated, the exception is raised.
  18. VersionNotFoundException - The exception is raised if an attempt is made to return a version that has since been removed from existence.

System.IO Exceptions in C#

  1. DirectoryNotFoundException - The exception is generated if a section of a file or directory cannot be located.
  2. DriveNotFoundException - The exception is raised if a disk or share is attempted to be accessed that is currently unavailable.
  3. EndOfStreamException - The exception is produced if an attempt is made to read data that has been written beyond the end of a stream.
  4. FileLoadException - This exception is issued if a managed assembly is located but cannot be loaded.
  5. FileNotFoundException - If an unsuccessful attempt is made to read from or write to a file that doesn’t exist on the disk, an exception is thrown.
  6. IOException - The exception is raised if there is a problem with the I/O.
  7. PathTooLongException - The error is issued if a pathname or filename is larger than the maximum length that has been pre-defined by the system.

System.Net Exceptions in C#

  1. HttpListenerException - If something goes wrong while processing an HTTP request, the exception is thrown.
  2. ProtocolViolationException - An exception is thrown if a network protocol is utilized improperly because of the error.
  3. WebException - The exception is issued if there is a problem when attempting to contact the network through a pluggable protocol.

System.Net.Mail Exceptions in C#

  1. SmtpException - Identifies the error condition that causes the to throw an exception when it cannot act.
  2. SmtpFailedRecipientException - This object represents the exception issued when the can’t finish sending a message or performing an action to a certain receiver.
  3. SmtpFailedRecipientsException - The exception is generated if an email is sent using a and cannot be sent to all recipients.

System.Net.NetworkInformation Exceptions in C#

  1. NetworkInformationException - The exception is raised if there is a failure in getting network information.
  2. PingException - The exception is generated whenever a method (or method) calls another method (or method) that generates an exception.

System.Resources Exceptions in C#

  1. MissingManifestResourceException - If the satellite assembly does not have enough resources for the neutral culture, an exception will be made because there is not enough room for a satellite assembly.
  2. MissingSatelliteAssemblyException - This rule does not apply when the neutral culture’s satellite assembly is not present, which is the only time it is appropriate to break it.
Author: Saad Aslam
Saad Aslam avatar Saad Aslam avatar

I'm a Flutter application developer with 1 year of professional experience in the field. I've created applications for both, android and iOS using AWS and Firebase, as the backend. I've written articles relating to the theoretical and problem-solving aspects of C, C++, and C#. I'm currently enrolled in an undergraduate program for Information Technology.

LinkedIn

Related Article - Csharp Exception