Complete C# Tutorial

Complete List of System Exceptions in C#

C# provides a rich set of built-in exceptions under the System namespace to handle various runtime errors. These exceptions help you identify and handle different error conditions in your code effectively.

Below is a comprehensive list of System exceptions in C#:

โœ… Commonly Used Exceptions

  1. ArgumentException โ€“ Invalid argument passed to a method.
  2. ArgumentNullException โ€“ Argument passed is null where it shouldn’t be.
  3. ArgumentOutOfRangeException โ€“ Argument value is out of acceptable range.
  4. ArithmeticException โ€“ Arithmetic operation errors (like division by zero).
  5. ArrayTypeMismatchException โ€“ Type mismatch while storing an element in an array.
  6. DivideByZeroException โ€“ Attempt to divide a number by zero.
  7. FormatException โ€“ Invalid format conversion (e.g., converting letters to a number).
  8. IndexOutOfRangeException โ€“ Accessing an invalid index in arrays or collections.
  9. InvalidCastException โ€“ Invalid type casting operation.
  10. InvalidOperationException โ€“ Method call is invalid for the object’s current state.
  11. KeyNotFoundException โ€“ Accessing a non-existent key in a dictionary.
  12. NotImplementedException โ€“ Method or operation is not implemented.
  13. NullReferenceException โ€“ Trying to access a member of a null object.
  14. ObjectDisposedException โ€“ Accessing a disposed object.
  15. OutOfMemoryException โ€“ Insufficient memory to continue execution.
  16. OverflowException โ€“ Arithmetic operation exceeds data type limits.
  17. StackOverflowException โ€“ Call stack limit exceeded (often due to recursion).

ย 

๐Ÿ“ File and I/O Related Exceptions

  1. DirectoryNotFoundException โ€“ Directory path is invalid or doesnโ€™t exist.
  2. DriveNotFoundException โ€“ Specified drive is unavailable.
  3. EndOfStreamException โ€“ End of a stream is reached unexpectedly.
  4. FileLoadException โ€“ Failure loading a file.
  5. FileNotFoundException โ€“ Requested file not found.
  6. IOException โ€“ General I/O operation errors.
  7. PathTooLongException โ€“ File or directory path is too long.

ย 

๐ŸŒ Security and Permissions Exceptions

  1. SecurityException โ€“ Security violation occurs.
  2. UnauthorizedAccessException โ€“ Unauthorized access to a resource.

ย 

๐Ÿงฎ Serialization and Reflection Exceptions

  1. InvalidProgramException โ€“ Code generation error by the compiler.
  2. MemberAccessException โ€“ Access to class members fails.
  3. MissingFieldException โ€“ Referencing a non-existent field.
  4. MissingMethodException โ€“ Referencing a non-existent method.
  5. NotSupportedException โ€“ Operation not supported.
  6. ReflectionTypeLoadException โ€“ Type loading error via reflection.
  7. TypeInitializationException โ€“ Failure during static constructor execution.
  8. TypeLoadException โ€“ Failure to load a specified type.

ย 

๐Ÿ›ก๏ธ Threading and Task Exceptions

  1. OperationCanceledException โ€“ Operation was canceled.
  2. ThreadAbortException โ€“ Thread is being aborted.
  3. ThreadInterruptedException โ€“ Interrupted while in a waiting state.
  4. TimeoutException โ€“ Operation took too long to complete.

ย 

๐Ÿ—„๏ธ Other Important Exceptions

  1. AccessViolationException โ€“ Unauthorized memory access.
  2. InsufficientExecutionStackException โ€“ Insufficient stack for execution.
  3. PlatformNotSupportedException โ€“ Operation not supported on the platform.
  4. RankException โ€“ Array dimension mismatch during an operation.
  5. SynchronizationLockException โ€“ Object synchronization error.
  6. UriFormatException โ€“ Invalid URI format.

๐Ÿ Conclusion

Phew! That was quite the journey through the land of common exceptions in C#, wasnโ€™t it? ๐ŸŽข We looked at how errors like NullReferenceException, FileNotFoundException, and ArgumentException occurโ€”and more importantlyโ€”how to handle them gracefully. ๐Ÿ’ช Remember, exceptions arenโ€™t your enemy; theyโ€™re helpful signals guiding you toward writing safer, more reliable code. ๐Ÿ›ก๏ธ

Hereโ€™s the takeaway: always expect the unexpected. Things like user input errors, missing files, or invalid data will sneak in. With proper exception handling, your programs will be rock solid and user-friendly. Your future self (and your users) will thank you! ๐Ÿ™Œ

ย 

๐Ÿ”ฎ Next what?

So, whatโ€™s next on this coding adventure? ๐ŸŽฏ In the upcoming chapter, weโ€™ll explore the checked and unchecked statements in Exception Handling. Curious about how to manage arithmetic overflows and avoid sneaky calculation errors? ๐Ÿ˜ฏ Donโ€™t miss outโ€”itโ€™s going to be eye-opening (and fun)! ๐ŸŒŸ

Stay curious, keep coding, and Iโ€™ll catch you in the next lesson! ๐Ÿš€๐Ÿ’ป

Leave a Comment

Share this Doc

Complete system exception

Or copy link