background image
<< Handling Exceptions | Exceptions - Performing more than one verification in a testcase >>
Exceptions - Using do...except
<< Handling Exceptions | Exceptions - Performing more than one verification in a testcase >>
210
User's Guide
9 H
ANDLING
E
XCEPTIONS
Using do...except
These runtime errors are called exceptions. They indicate that something did
not go as expected in a script. They can be generated automatically by
SilkTest, such as when a verification fails, when there is a division by zero in
a script, or when an invalid function is called.
You can also generate exceptions explicitly in a script.
However, suppose you don't want SilkTest to transfer control to the recovery
system when an exception is generated, but instead want to trap the exception
and handle it yourself. To do this, you use the 4Test do...except statement.
Using do...except
Using do...except you can handle exceptions locally, instead of passing
control to SilkTest's built-in error handler (which is part of the recovery
system). The statement has the following syntax:
do
statements
except
statements
If an exception is raised in the do clause of the statement, control is
immediately passed to the except clause, instead of to the recovery system. If
no exception is raised in the do clause of the statement, control is passed to
the line after the except clause--the statements in the except clause are not
executed.
. . .
do
exception raised here
except
statements
. . .
control passes
. . .
do
no exception raised here
except
statements
. . .
control passes
into except clause
to first statement
after except clause