Updated project.
[mono.git] / mcs / btests / ExceptionHandlingA.vb
1 Imports System\r
2 \r
3 Module ExceptionHandlingA\r
4 \r
5     Sub Main()\r
6 \r
7         ' Finally block is executed regardless of how execution \r
8         ' leaves the Try statement\r
9 \r
10         ' Case 1: through the end of Try block\r
11         Dim i As Integer = 0\r
12         Try\r
13             i = i + 1\r
14         Finally\r
15             i = i + 2\r
16         End Try\r
17 \r
18         If i <> 3 Then\r
19             Throw New Exception("#EHA1 - Finally block not executed")\r
20         End If\r
21 \r
22         ' Case 2: through the end of Catch block\r
23         Try\r
24             i = i / 0\r
25         Catch e As Exception\r
26             i = i * 2\r
27         Finally\r
28             i = i * 3 / 2\r
29         End Try\r
30 \r
31         If i <> 9 Then\r
32             Throw New Exception("#EHA2 - Finally block not executed")\r
33         End If\r
34 \r
35         ' Case 3: through an Exit Try statement\r
36         Try\r
37             i = i / 9 * 2\r
38             Exit Try\r
39         Catch e As Exception\r
40             Console.WriteLine(e.Message)\r
41         Finally\r
42             i = i / 2\r
43         End Try\r
44 \r
45         If i <> 1 Then\r
46             Throw New Exception("#EHA3 - Finally block not executed")\r
47         End If\r
48 \r
49         ' Case 4: through a GoTo statement\r
50         Try\r
51             i = i - 1\r
52             GoTo label\r
53         Catch e As Exception\r
54             Console.WriteLine(e.Message)\r
55         Finally\r
56             i = i + 1\r
57         End Try\r
58 label:\r
59         If i <> 1 Then\r
60             Throw New Exception("#EHA4 - Finally block not executed")\r
61         End If\r
62 \r
63         ' Case 5: by not handling a thrown exception\r
64         Try\r
65             Try\r
66                 i = 5\r
67                 Throw New Exception("EE")\r
68             Finally\r
69                 i = i * 5\r
70             End Try\r
71         Catch e As Exception\r
72             i = i * 2\r
73         End Try\r
74 \r
75         If i <> 50 Then\r
76             Throw New Exception("#EHA5 - Finally block not exceuted")\r
77         End If\r
78 \r
79     End Sub\r
80 \r
81 End Module