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

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...