Exception handling syntax: Difference between revisions

Content deleted Content added
ATS: fix syntaxhighlight error
spelling (WP:Typo Team)
Line 1,118:
On Error Resume Next 'Object Err is set, but execution continues on next command. You can still use Err object to check error state.
'...
Err.Raise 6 ' Generate an "Overflow" error using buildbuilt-in object Err. If there is no error handler, calling procedure can catch exception by same syntax
'...
 
Line 1,136:
 
MsgBox Err.Number & " " & Err.Source & " " & Erl & " " & Err.Description & " " & Err.LastDllError 'show message box with important error properties
'Erl is VB6 buildbuilt-in line number global variable (if used). Typically is used some kind of IDE Add-In, which labels every code line with number before compilation
Resume FinallyLabel
</syntaxhighlight>
Line 1,144:
With New Try: On Error Resume Next 'Create new object of class "Try" and use it. Then set this object as default. Can be "Dim T As New Try: ... ... T.Catch
'do Something (only one statement recommended)
.Catch: On Error GoTo 0: Select Case .Number 'Call Try.Catch() procedure. Then switch off error handling. Then use "switch-like" statement on result of Try.Number property (value of property Err.Number of buildbuilt-in Err object)
Case SOME_ERRORNUMBER
'exception handling