Per molti metodi e proprietà dell'API Rational ClearQuest, è necessario esaminare il valore riportato per confermare se la chiamata riporta o no un errore.
Ad esempio, il metodo SetFieldValue dell'oggetto Entità viene definito in modo che riporti un valore di stringa. Viene riportata una stringa vuota se sono consentite modifiche al campo e l'operazione ha esito positivo; altrimenti, se l'operazione non riesce, questo metodo riporta una stringa contenente una spiegazione dell'errore.
Per intercettare l'errore, il codice deve esaminare il valore riportato. Ad esempio:
strRetVal = SetfieldValue ("Invalid_field", "Invalid value")
If "" <> strRetVal Then
REM handle the error
End If
Se viene specificato un campo non corretto, viene riportato un errore. Ad esempio:
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...
}
Per VBScript, utilizzare un'istruzione On Error per rilevare le eccezioni. Per ulteriori informazioni, consultare Gestione degli errori VBScript e Gestione degli errori Perl. Esempio di hook Action Commit fornisce esempi di gestione errori e eccezioni quando si richiama il metodo Commit.