using System; public class Test{ public static void Requires<TException>(bool condition, string message) where TException : Exception { Exception exception = (Exception)Activator.CreateInstance(typeof(TException),message); throw exception; } public static void Main() { try { Requires<ArgumentNullException>(true,"Test"); } catch(Exception e) { Console.WriteLine(e); } }}
Standard input is empty
System.ArgumentNullException: Argument cannot be null. Parameter name: Test at Test.Requires[ArgumentNullException] (Boolean condition, System.String message) [0x00000] in <filename unknown>:0 at Test.Main () [0x00000] in <filename unknown>:0
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!