background image
<< Exceptions - the GetSelText method | Exceptions - Writing an error-handling function >>
Exceptions - Trapping the exception number
<< Exceptions - the GetSelText method | Exceptions - Writing an error-handling function >>
214
User's Guide
9 H
ANDLING
E
XCEPTIONS
Trapping the exception number
Trapping the exception number
Each built-in exception has a name and a number (they are defined as an
enumerated data type,
EXCEPTION
). For example, the exception generated
when a verify fails is
E_VERIFY
(-13700), and the exception generated when
there is a division by zero is
E_DIVIDE_BY_ZERO
(-11500).
Note All exceptions are defined in 4test.inc, in the directory where
you installed SilkTest. They are described in the topic "Exception
values" in online Help.
You can use the ExceptNum function to test for which exception has been
generated and, perhaps, take different actions based on the exception. You
would capture the exception in a do...except statement then check for the
exception using ExceptNum.
For example, if you want to ignore the exception
E_WINDOW_SIZE_
INVALID
, which is generated when a window is too big for the screen, you
could do something like this:
do
Open.Invoke ()
except
if (ExceptNum () != E_WINDOW_SIZE_INVALID)
reraise
If the exception is not
E_WINDOW_SIZE_INVALID
, the exception is reraised
(and passed to the recovery system for processing). If the exception is
E_
WINDOW_SIZE_INVALID
, it is ignored.
Writing an error-handling function
If you want to customize your error processing, you will probably want to
write your own error-handling function, which you can reuse in many scripts.
For example, you might want to print the text associated with the exception
as well as the function calls that generated the exception. The following
testcase illustrates this.
testcase VerifyTest ()
STRING sTestValue = "xxx"
STRING sExpectedValue = "yyy"
CompValues (sExpectedValue, sTestValue)
CompValues (STRING sExpectedValue, STRING sTestValue)
do