|Non-Confidential||PDF version||ARM DUI0446Z|
|Home > Debugging with Scripts > Defining the validation method for use case scripts|
The method defined using the
$Validation$ tag names a method in the use case script which provides validation for the use case.
The validation method takes a single parameter, called
which can be used to access the options supplied to the script.
The example shows a validation method called
myValidation in the use case definition block. The validation method is
used to validate the set of options supplied to the use case script.
... $Validation$ myValidation ...
def myValidation(options): # Get the options which define the start and end of a trace range # These options have been defined in the function defined in the $Options$ tag start = options.getOptionValue("options.traceRange.start") end = options.getOptionValue("options.traceRange.end") # Conditional check for validation if(start >= end): # Report a specific error in the use case script if the validation check fails UseCaseScript.error("The trace range start must be before the end")
It is important that the function that supplies the validation takes a single parameter, which is the use case script object, used to access the options defined for use in the script.
$Validation$ tag is defined, and the
method referred to in this tag is not present in the script or the validation
function takes the wrong number of arguments, an error occurs when running the
This validation example throws an error specific to use case scripts. If validation is not successful, for example start >= end, in our script, the DS-5 command-line displays:
UseCaseError: The trace range start must be before the
It is possible not to use the built-in use case error reporting and throw a standard Jython or Java error such as:
raise RuntimeError("Validation was
This displays an error in the DS-5 command-line:
RuntimeError: Validation was unsuccessful
However, it is recommended to use the built-in use case script error reporting so that a clear user-defined error is raised that originates from the use case script.