For many methods and properties of the Rational® ClearQuest® API, you must check the return value to validate whether or not the call returns an error.
if (!defined($result)) { ... };
to detect this condition.For example the Entity object SetFieldValue method is defined as returning a String value. It returns an empty String if changes to the field are permitted and the operation is successful; otherwise, if the operation fails, this method returns a String containing an explanation of the error.
To trap the error, your code must check the return value. For example:
strRetVal = SetfieldValue ("Invalid_field", "Invalid value")
If "" <> strRetVal Then
REM handle the error
End If
If an incorrect field is specified, an error is returned. For example:
The Defect SAMPL00000123 does not have a field named "Invalid_field".
# trap exceptions and error message strings
# ...
eval { $RetVal = ${$CQEntity}->Validate(); };
# EXCEPTION information is in $@
# RetVal is either an empty string or contains a failure message string
if ($@){
print "Exception: '$@'\n";
# other exception handling goes here...
}
if ($RetVal eq "")
{# success...
}
else {
# failure...
# return the message string here...
}
For VBScript, use an On Error statement to trap exceptions. For more information, see VBScript error handling and Perl error handling. The Action commit hook example provides examples of error and exception handling when calling the Commit method.