Example Script - Error Handling

The following script illustrates how you can construct a script to include error handling.

To include basic error handling in a script, include a Catch ex As Exception statement in your script followed by the object and the parameters that you want to test for an exception. For example, to test the Notepad application font type, you might type the following code:
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
Note: This example is meant to illustrate how you can implement basic error handling. You must add an application configuration and make any necessary adjustments for your test application to successfully implement this code. If you cut and paste this example into your script, an error occurs because the application configuration is missing.