1 using System; 2 3 public class MyEx : Exception { MyEx()4 public MyEx () {} 5 } 6 7 public class Ex { 8 test(int a)9 public static int test (int a) { 10 int res; 11 int fin = 0; 12 try { 13 res = 10/a; 14 throw new MyEx (); 15 } catch (Exception ex) { 16 ex = new MyEx (); 17 throw; 18 } finally { 19 fin = 1; 20 } 21 return res; 22 } Main()23 public static int Main () { 24 int catched = 0; 25 try { 26 test (1); 27 } catch (MyEx ex) { 28 catched = 1; 29 } 30 if (catched != 1) 31 return 2; 32 try { 33 test (0); 34 } catch (MyEx ex) { 35 catched = 2; 36 } catch { 37 // we should get here because rethrow rethrows the dividebyzero ex 38 // not the exception assigned to the local var (a MyEx) 39 catched = 3; 40 } 41 if (catched != 3) 42 return 3; 43 return 0; 44 } 45 } 46 47 48