Share via


Compiler Error CS0156

A throw statement with no arguments is not allowed in a finally clause that is nested inside the nearest enclosing catch clause

A throw statement with no parameters can only appear in a catch clause that takes no parameters.

For more information, see Exception Handling Statements and Exceptions and Exception Handling (C# Programming Guide).

The following sample generates CS0156:

// CS0156.cs
using System;

namespace MyNamespace
{
   public class MyClass2 : Exception
   {
   }

   public class MyClass
   {
      public static void Main()
      {
         try
         {
            throw;   // CS0156
         }

         catch(MyClass2)
         {
            throw;   // this throw is valid
         }
      }
   }
}