fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5.  
  6. public static void Requires<TException>(bool condition, string message)
  7. where TException : Exception
  8. {
  9. Exception exception = (Exception)Activator.CreateInstance(typeof(TException),message);
  10. throw exception;
  11. }
  12.  
  13. public static void Main()
  14. {
  15. try
  16. {
  17. Requires<ArgumentNullException>(true,"Test");
  18. }
  19. catch(Exception e)
  20. {
  21. Console.WriteLine(e);
  22. }
  23.  
  24. }
  25. }
Success #stdin #stdout 0.08s 24208KB
stdin
Standard input is empty
stdout
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