Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

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.