Exception Types

Explore different types of exceptions.

The Exception class

An exception is nothing more than a class. So, when an exception is generated, an object of a given exception type is created and thrown.

The base class of all exceptions in .NET is the Exception class. It defines several properties that can be used to obtain more information about the exception that’s occurred.

  • InnerException: This stores the exception object that caused the current exception.
  • Message: This stores the exception’s textual information.
  • Source: This stores information about an object or an assembly where the exception was thrown.
  • StackTrace: This stores the entire method call stack that led to the exception.
  • TargetSite: This stores the method name where the exception occurred.

Let’s see the contents of the properties using the following example:

Get hands-on with 1200+ tech skills courses.