Search⌘ K
AI Features

Exception Types

Explore different exception types in C# including common ones like NullReferenceException and DivideByZeroException. Learn how to use try, catch, and finally blocks effectively and understand the importance of catch block order for handling errors in .NET.

An exception is an object that wraps error details. When an error occurs, the runtime creates and throws an object of a specific exception type.

The Exception class

The base class of all exceptions in .NET is the System.Exception class. It defines several properties that help us understand what went wrong.

  • Message: A text description of the error.

  • StackTrace: A string showing the method call sequence that led to the exception.

  • Source: The name of the application or object that caused the error.

  • InnerException: If an exception was triggered by another exception, this property holds the original error.

  • TargetSite: ...