/
generic-exceptions.2.cs
76 lines (65 loc) · 1.38 KB
/
generic-exceptions.2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
public class GenExc<S,T> : Exception {
}
public delegate void ThrowDelegate ();
public class Gen<T> {
public void catcher<S> (ThrowDelegate thrower) {
try {
thrower ();
}
catch (GenExc<S,T>) {
}
}
public static void staticCatcher<S> (ThrowDelegate thrower) {
try {
thrower ();
}
catch (GenExc<S,T>) {
}
}
}
public class main {
static void throwObjectObject () {
throw new GenExc<object, object> ();
}
static void throwStringObject () {
throw new GenExc<string, object> ();
}
static int Main () {
Gen<object> go = new Gen<object> ();
try {
go.catcher<object> (new ThrowDelegate (main.throwObjectObject));
Gen<object>.staticCatcher<object> (new ThrowDelegate (main.throwObjectObject));
go.catcher<string> (new ThrowDelegate (main.throwStringObject));
Gen<object>.staticCatcher<string> (new ThrowDelegate (main.throwStringObject));
}
catch {
return 1;
}
try {
go.catcher<object> (new ThrowDelegate (main.throwStringObject));
return 1;
}
catch {
}
try {
Gen<object>.staticCatcher<object> (new ThrowDelegate (main.throwStringObject));
return 1;
}
catch {
}
try {
go.catcher<string> (new ThrowDelegate (main.throwObjectObject));
return 1;
}
catch {
}
try {
Gen<object>.staticCatcher<string> (new ThrowDelegate (main.throwObjectObject));
return 1;
}
catch {
}
return 0;
}
}