**** Merged from MCS ****
[mono-project.git] / mcs / btests / ExceptionHandlingC.vb
blob17f0a38caa78c34d3f836db97f39e122d59a99bd
2 Imports System
3 Imports Microsoft.VisualBasic
5 Module ExceptionHandlingC
7 Sub f1()
8 On Error GoTo ErrorHandler
9 Dim i As Integer = 0
10 i = 1 / i
11 Console.WriteLine(i)
12 Exit Sub
13 ErrorHandler:
14 Throw New Exception("AA")
15 Resume Next
16 End Sub
18 Sub f2()
19 On Error GoTo ErrorHandler
20 f1()
21 Exit Sub
22 ErrorHandler:
23 If Err.Description <> "AA" Then
24 Throw New Exception("#EHC1 - Error statement failed")
25 End If
26 Resume Next
27 End Sub
29 Sub f3()
30 On Error GoTo ErrorHandler
31 Throw New DivideByZeroException()
32 Exit Sub
33 ErrorHandler:
34 If Not TypeOf Err.GetException Is DivideByZeroException Then
35 Throw New Exception("#EHC2 - Error statement failed")
36 End If
37 Resume Next
38 End Sub
40 Sub f4()
41 On Error GoTo ErrorHandler
42 Dim i As Integer = 0
43 i = 5 / i
44 On Error GoTo 0
45 If i <> 1 Then
46 Throw New Exception("#EHC3 - Error Statement failed")
47 End If
48 Exit Sub
49 ErrorHandler:
50 i = 5
51 Resume ' Execution resumes with the statement that caused the error
52 End Sub
54 Sub f5()
55 On Error GoTo ErrorHandler
56 Error 6 ' Overflow Exception
57 Exit Sub
58 ErrorHandler:
59 If Err.Number <> 6 Then
60 Throw New Exception("#EHC4 - Error Statement failed")
61 End If
62 Resume Next
63 End Sub
65 Sub f6()
66 On Error GoTo ErrorHandler
67 Dim i As Integer = 0, j As Integer
68 i = 1 / i
70 On Error GoTo 0 ' Disable error handler
71 On Error Resume Next
73 i = 0
74 i = 1 / i ' create error
75 If Err.Number = 6 Then ' handle error
76 Err.Clear()
77 Else
78 Throw New Exception("#EHC5 - Error Statement failed")
79 End If
81 i = 1 / i
82 On Error GoTo -1
83 If Err.Number <> 0 Then
84 Throw New Exception("#EHC6 - Error Statement failed")
85 End If
87 Exit Sub
88 ErrorHandler:
89 Select Case Err.Number
90 Case 6
91 i = 1
92 Case Else
93 Throw New Exception("#EHC7 - Error Statement failed")
94 End Select
95 Resume
96 End Sub
98 Sub Main()
99 f2() : f3() : f4() : f5() : f6()
100 End Sub
102 End Module