Flow-control structures: Difference between revisions

Line 542:
Console.WriteLine(x)
End Sub
 
=== On Error Goto ===
 
This brances in the event of an error. Usually there is an Exit (Sub|Function) to seperate the normal code from the error handling code
 
Sub foo()
On Error GoTo label
'do something dangerous
Exit Sub
label:
Console.WriteLine("Operation Failed")
End Sub
 
''This style of code is rarely used.''
 
=== On Error Resume Next ===
 
This performs a sequence of actions. If any action fails, the exception is discarded and next operation is performed.
 
Sub foo2()
On Error Resume Next
Operation1()
Operation2()
Operation3()
Operation4()
End Sub
 
''This style of code is rarely used.''