I'd like to share a solution I found to a problem I had. Maybe it will help you too.
I wanted to make my script more robust, but I couldn't think of how to reliably check for an AcroQTP object to exist on the form before I had the form use it. The obvious answer
if( AcroXFAButton("blah").Exist ) ...
didn't work, because Exist would always return TRUE for AcroXFA objects. I had developed some very ugly workarounds in my script.
Then I decided to try using VBScript's Error handling to catch the error:
' PROTOTYPE: VerifyFieldExists( objField )
' PURPOSE: Checks to see if a particular XFA object exists, so we can take appropriate action in the caller.
' Prevents encountering a "Run error: The server threw an exception."
' Returns TRUE if exists or FALSE if it doesn't.
' if( not VerifyFieldExists( PDFDoc("TestForm").AcroXFAForm("form").AcroXFAForm("sfPart2") ) then
' end if
Function VerifyFieldExists( objField )
On Error Resume Next ' Enable error-handling
objField.getROProperty("afpid") ' If it doesn't exist this will cause an error
If Err.Number <> 0 Then
VerifyFieldExists = FALSE
VerifyFieldExists = TRUE
On Error Goto 0 ' Disable error-handling
This works very well, and my scripts are much more robust and more efficient now. (I don't call this function for every XFA object I access, but when there's a good chance the script may break and when there's an obvious point of recovery for the script.)
If you found generally-useful solutions to problems you encountered, please consider sharing them here.