Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0156 

Error Message

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 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
         }
      }
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft