In C#, exception handling is implemented using try-catch blocks.

The try block contains the code that may throw an exception. If an exception occurs, it is caught by the catch block and appropriate actions can be taken to handle the exception.

Here is an example of how to implement exception handling in C#:

“`csharp
try
{
// Code that may throw an exception
// For example, accessing an array out of bounds
int[] numbers = { 1, 2, 3 };
Console.WriteLine(numbers[3]);
}
catch (IndexOutOfRangeException e)
{
// Handle the exception
Console.WriteLine(“An exception occurred: ” + e.Message);
}
“`

In this example, the code inside the try block attempts to access an element of an array that is out of bounds. This will throw an `IndexOutOfRangeException` exception.

The catch block specifies the type of exception to catch (`IndexOutOfRangeException` in this case) and provides a variable (`e` in this case) that can be used to access information about the exception. The catch block then handles the exception by printing an error message.

It is also possible to have multiple catch blocks to handle different types of exceptions. The catch blocks are evaluated in the order they appear, and the first catch block that matches the type of the thrown exception is executed.

“`csharp
try
{
// Code that may throw an exception
// For example, dividing by zero
int x = 10;
int y = 0;
int result = x / y;
}
catch (DivideByZeroException e)
{
// Handle divide by zero exception
Console.WriteLine(“Divide by zero exception occurred: ” + e.Message);
}
catch (Exception e)
{
// Handle any other exception
Console.WriteLine(“An exception occurred: ” + e.Message);
}
“`

In this example, if a `DivideByZeroException` occurs, the first catch block is executed. If any other type of exception occurs, the second catch block is executed. The second catch block uses the base `Exception` type to catch any exception that is not specifically caught by the first catch block.