KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to catch SOAP method errors using the 4D ON ERR CALL () command
PRODUCT: 4D | VERSION: 2003.2 | PLATFORM: Mac & Win
Published On: March 18, 2004

The 4D ON ERR CALL() command allows developers to handle errors more elegantly. It gives the control over to the developers to handle the errors rather then letting 4D handle them. More information regarding the ON ERR CALL is located at: https://www.4d.com/docs/CMU/CMU00155.HTM. Here is a sample of the code:

C_BLOB($1)
C_BLOB($0)
C_TEXT($errorMsg)

ON ERR CALL("Amz_Error")
<>errorNum:=2

SET WEB SERVICE PARAMETER("BlobAsXMLIn";$1)

CALL WEB SERVICE("https://soap.amazon.com/onca/soap2";"https://soap.amazon.com";
"ActorSearchRequest";"https://soap.amazon.com";Web Service Manual )

If (OK=1)
  GET WEB SERVICE RESULT($0;"BlobAsXMLOut";*) ` Memory clean-up on the final return value.
End if

ON ERR CALL("")
errorMsg:= Get Web Service error info(1)

The ON ERR CALL() command works like this-The SOAP methods executes line by line skipping over the ON ERR CALL() command until it returns an error (soap fault). Once the error has been detected, the SOAP method jumps to the ON ERR CALL ("Amz_Error") command and executes the method that has been passed to the command to handle the error. Once that method has completed, it returns to the ON ERR CALL("") and continues at that particular line. To display the correct error message, use the Get Web Service error info command. This particular command returns the information about the last error encountered in the SOAP method. This allows you to display errors more elegantly.