Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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
{
}
}
}
}