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 Exceptions and Exception Handling.
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
{
}
}
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: