fork download
  1. using System;
  2. using System.Collections;
  3.  
  4. class ExceptionTest : IComparer
  5. {
  6.  
  7. public int Compare(object x, object y)
  8. {
  9. throw new Exception("test exception");
  10. }
  11. }
  12.  
  13. public class Test
  14. {
  15. public static void Main()
  16. {
  17. int[] intarray = {1, 3, 7, 10, 11, 99, 30, 5};
  18. ExceptionTest exceptionTest =new ExceptionTest();
  19. try
  20. {
  21. Array.Sort(intarray, exceptionTest);
  22. }
  23. catch (Exception e)
  24. {
  25.  
  26. Console.WriteLine("caught Exception from ExceptionTest class !");
  27. Console.WriteLine(e.Message);
  28. Console.ReadLine();
  29. }
  30. }
  31. }
Success #stdin #stdout 0.04s 24152KB
stdin
Standard input is empty
stdout
caught Exception from ExceptionTest class !
The comparer threw an exception.