HomeCSharpC# Error CS0155 – The type caught or thrown must be derived from System.Exception

C# Error CS0155 – The type caught or thrown must be derived from System.Exception

C# Compiler Error

CS0155 – The type caught or thrown must be derived from System.Exception

Reason for the Error

You will receive this error in C# when you attempt to use a type with-in the Catch Block parameter that does not derive from System.Exception class.

For example, the below code snippet will result with the error code CS0155 because the class DeveloperPublishException is passed to the catch block but the class DeveloperPublishException doesnot derive from System.Exception.

namespace ConsoleApp2
{
    public class DeveloperPublishException
    {
      
    }
    class Program
    {
        public static void Main()
        {
            try
            {

            }
            catch(DeveloperPublishException ex)
            {

            }

        }

    }
    
}
C# Error CS0155 – The type caught or thrown must be derived from System.Exception

Error CS0155 The type caught or thrown must be derived from System.Exception ConsoleApp2 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp2\Program.cs 15 Active

Solution

To fix this error, ensure that the type that you pass with-in the catch block is derived from the System.Exception.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...