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