C# Compiler Error
CS0156 – A throw statement with no arguments is not allowed outside of a catch clause
Reason for the Error
You will receive this error in C# when you try to throw an exception outside of a catch block.
For example, try compiling the below code snippet.
using System; namespace ConsoleApp2 { public class DeveloperPublishException { } class Program { public static void Main() { try { throw; } catch (Exception ex) { } } } }
You will receive the C# error code CS0156 because the throw keyword was used outside the catch block (inside the try)
Error CS0156 A throw statement with no arguments is not allowed outside of a catch clause ConsoleApp2 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp2\Program.cs 15 Active
Solution
To fix the error, move the logic of where you are calling the throw without parameters inside the catch block.