The following script illustrates how you can construct a script to include error handling.
Public Module Main
Dim _desktop As Desktop = Agent.Desktop
Public Sub Main()
With _desktop.Window("@caption='Untitled - Notepad'")
.TextField().TypeKeys("test", 0, False)
.MenuItem("@caption='Font'").Select()
Try
With .Dialog("@caption='Font1'") ' throws an exception because such a dialog does not exist
.ComboBox("@caption='Font style:'").Select("Regular")
.ComboBox("@caption='Size:'").Select("14")
.PushButton("@caption='Cancel'").Select()
End With
Catch ex As Exception
With .Dialog("@caption='Font'")
.ComboBox("@caption='Font style:'").Select("Regular")
.ComboBox("@caption='Size:'").Select("14")
.PushButton("@caption='Cancel'").Select()
End With
End Try
End With
End Sub
End Module