background image
<< Exceptions - Adding to the default error handling | Exceptions - Trapping the exception number >>
Exceptions - the GetSelText method
<< Exceptions - Adding to the default error handling | Exceptions - Trapping the exception number >>
User's Guide
213
9 H
ANDLING
E
XCEPTIONS
Adding to the default error handling
Find.CaseSensitive.SetState (Data.bCase)
Find.Direction.Select (Data.sDirection)
Find.FindNext.Click ()
do
MessageBox.Message.VerifyValue (Data.sMessage)
except
sMatch = DocumentWindow.Document.GetSelText ()
if (sMatch != "")
Print ("Found " + sMatch + " not " + Data.sPattern)
reraise
MessageBox.OK.Click ()
Find.Cancel.Click ()
TextEditor.File.Close.Pick ()
MessageBox.No.Click ()
As the example shows, following the do keyword is the verification
statement, and following the except keyword are the 4Test statements that
handle the exception. The exception-handling statements in this example do
the following:
1
Call the GetSelText method to determine what text, if any, is currently
selected in the document.
2
If the return value from the GetSelText method is not an empty string, it
means that the application found a false match. If this is the case, then
print the false match and the search string to the results file.
3
Reraise the exception to transfer control to the recovery system and
terminate the testcase.
reraise
The reraise statement raises the most recent exception again and passes
control to the next exception handler (in the preceding testcase, it passes
control to the built-in recovery system). We used reraise in the preceding
testcase because if the exception-handling code does not explicitly reraise the
exception, flow of control passes to the next statement in the testcase.
So this example performs a test after an exception is raised, prints a statement
to the results file if text was selected, then calls the recovery system, which
terminates the testcase, logs the error, and restores the test application to its
default base state.