Exceptions: Difference between revisions
Content deleted Content added
Line 3,081:
End Sub</lang>
=={{header|
For historical reasons, Exceptions are called 'Errors' in VBA and VB Classic.
Line 3,100:
<lang vba>Sub bar1()
'by convention, a simple handler
On Error
MsgBox " No Error"
Exit Sub
catch:
'handle all exceptions
MsgBox Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub
Sub bar2()
'a more complex handler, illustrating some of the flexibility of VBA exception handling
100
200
'finally block may be placed anywhere: this is complexity for it's own sake:
catch:
If
Resume
Select Case
' handle exceptions of type 1050
Case vbObjectError
' handle exceptions of type 1051
' handle any type of exception not handled by above catches or line numbers
MsgBox Err.Number & vbCrLf & Err.Description
End Select
Resume finally
End If
finally:
end_try:
'by convention, often just a drop through from the catch block
=={{header|zkl}}==
|