An exception is simply a class in C#. This has a few properties and methods. The four most commonly used properties are as follows:
Property | Description |
Message | This contains what the exception is about. |
StackTrace | This contains the method call-stack information. |
TargetSite | This gives an object that contains the method where the exception happened. |
InnerException | This gives the instance of the exception that caused the exception. |
Exception class properties and methods
One of the most popular methods in this class is ToString(). This method returns a string that contains information about the exception. The exception is easier to read and understand when it is represented in string format.
Let's look at an example of using these properties and methods:
using System;
namespace ExceptionCode
{
class Program
{
static void Main(string[] args)
{
try
...