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:
// 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
}
}
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: