This documentation is archived and is not being maintained.

Compiler Error CS0156

A throw statement with no arguments is not allowed outside of a 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.

The following sample generates CS0156:

// CS0156.cs
using System;

namespace x
{
   public class b : Exception
   {
   }

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

         catch(b)
         {
            throw;   // this throw is valid
         }
      }
   }
}
Show: