This documentation is archived and is not being maintained.

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.

The following sample generates CS0155:

// CS0155.cs
using System;

namespace x
{
   public class b
   // try the following line instead
   // public class b : Exception
   {
   }

   public class a
   {
      public static void Main()
      {
         try
         {
         }

         catch(b)   // CS0155, resolves if you derive b from Exception
         {
         }
      }
   }
}
Show: