fork download
  1. using System;
  2.  
  3. class Test{
  4. public static void Main(){
  5. new Test().F();
  6. }
  7.  
  8. event EventHandler ev1;
  9. EventHandler ev2;
  10.  
  11. void F(){
  12. ev1 += Handler1;
  13. ev1 += Handler2;
  14. ev1 += Handler3;
  15. try{ev1(null,null);}catch(Exception ex){Console.WriteLine("catch["+ex.Message+"]");}
  16.  
  17. ev2 = chain(ev2, Handler1);
  18. ev2 = chain(ev2, Handler2);
  19. ev2 = chain(ev2, Handler3);
  20. try{ev2(null,null);}catch(Exception ex){Console.WriteLine("catch["+ex.Message+"]");}
  21. }
  22.  
  23. static EventHandler chain(EventHandler a, EventHandler b){
  24. return (Object sender, EventArgs e) => {if(a!=null){a(sender, e);} if(b!=null){b(sender, e);}};
  25. }
  26.  
  27. static void Handler1(Object sender, EventArgs e){
  28. Console.WriteLine("1");
  29. }
  30. static void Handler2(Object sender, EventArgs e){
  31. Console.WriteLine("2");
  32. throw new Exception("ex2");
  33. }
  34. static void Handler3(Object sender, EventArgs e){
  35. Console.WriteLine("3");
  36. }
  37. }
Success #stdin #stdout 0.04s 36872KB
stdin
Standard input is empty
stdout
1
2
catch[ex2]
1
2
catch[ex2]