Edit

Share via


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 Exceptions and Exception Handling.

The following sample generates CS0156:

C#
// 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  
         }  
      }  
   }  
}