Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0155

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

An attempt was made to pass a data type that does not derive from System.Exception into a catch block. Only data types that derive from System.Exception can be passed into a catch block. For more information, see Exception Handling Statements and Exceptions and Exception Handling (C# Programming Guide).

The following sample generates CS0155:

// CS0155.cs
using System;

namespace MyNamespace
{
    public class MyClass2
    // try the following line instead
    // public class MyClass2 : Exception
    {
    }
    public class MyClass
    {
        public static void Main()
        {
            try
            {
            }
            catch (MyClass2)   // CS0155, resolves if you derive MyClass2 from Exception
            {
            }
        }
    }
}

Community Additions

ADD
Show:
© 2015 Microsoft