3 Imports Microsoft
.VisualBasic
5 Module ExceptionHandlingC
8 On Error GoTo ErrorHandler
14 Throw
New Exception("AA")
19 On Error GoTo ErrorHandler
23 If Err
.Description
<> "AA" Then
24 Throw
New Exception("#EHC1 - Error statement failed")
30 On Error GoTo ErrorHandler
31 Throw
New DivideByZeroException()
34 If Not TypeOf Err
.GetException Is DivideByZeroException
Then
35 Throw
New Exception("#EHC2 - Error statement failed")
41 On Error GoTo ErrorHandler
46 Throw
New Exception("#EHC3 - Error Statement failed")
51 Resume ' Execution resumes with the statement that caused the error
55 On Error GoTo ErrorHandler
56 Error 6 ' Overflow Exception
59 If Err
.Number
<> 6 Then
60 Throw
New Exception("#EHC4 - Error Statement failed")
66 On Error GoTo ErrorHandler
67 Dim i
As Integer = 0, j
As Integer
70 On Error GoTo 0 ' Disable error handler
74 i
= 1 / i
' create error
75 If Err
.Number
= 6 Then ' handle error
78 Throw
New Exception("#EHC5 - Error Statement failed")
83 If Err
.Number
<> 0 Then
84 Throw
New Exception("#EHC6 - Error Statement failed")
89 Select Case Err
.Number
93 Throw
New Exception("#EHC7 - Error Statement failed")
99 f2() : f3() : f4() : f5() : f6()