Kbase P103068: How to return errors from the AppServer to a .Net client
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  4/11/2005 |
|
Status: Unverified
GOAL:
How to return errors from the AppServer to a .Net client
FIX:
When a 4GL program that is run on the AppServer encounters an error that does not generate either a STOP or QUIT condition the error message will be sent to the AppServer log file as the condition is not considered to be critical. An example of such an error would be a FIND statement which has no NO-ERROR phrase and when executed fails to find a record which in turn would cause error 565 to be written to the AppServer log file.
The key to returning these kinds of errors back to the client for handling is to ensure that the program being executed on the AppServer is wrapped inside of a DO ON block. The following 4GL code will catch the possible failure of the FIND statement to return a record and the resulting error (565) will be returned to the .Net client via the .Net proxies ProcReturnString method:
DEFINE INPUT PARAMETER pi-ClCode AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER pi-TrapError AS LOGICAL NO-UNDO.
DEFINE OUTPUT PARAMETER po-CliName AS CHARACTER NO-UNDO.
DO ON ERROR UNDO, RETURN ERROR ERROR-STATUS:GET-MESSAGE(1)
ON STOP UNDO, RETURN ERROR ERROR-STATUS:GET-MESSAGE(1):
IF pi-TrapError THEN
DO:
FIND FIRST Customer WHERE Customer.CustNum = pi-ClCode NO-LOCK NO-ERROR.
/* The ProcReturnString method of the .Net proxy will have the */
/* value "Client not found" if no such record exists. */
IF NOT AVAILABLE(Customer) THEN
RETURN "Client not found".
END.
ELSE
/* The ProcReturnString method of the .Net proxy will have the */
/* text of error 565 (which is returned when a FIND fails and */
/* the error is not suppressed). */
FIND FIRST Customer WHERE Customer.CustNum = pi-ClCode NO-LOCK.
ASSIGN po-CliName = Customer.Name.
END.
The following VB.NET code shows how to catch the error string returned by the above 4GL program as this kind of error handling will not cause an exception to be thrown in the .Net client:
Sub Main()
Dim vAppServer As PhilProxy, vResult As String, vClientName As String
Try
vAppServer = New PhilProxy("AppServer://localhost:5162/StateLess", "", "", "")
vResult = vAppServer.wmGetClientName(-1, False, vClientName)
Debug.WriteLine(vResult)
Debug.WriteLine(vClientName)
Debug.WriteLine(vAppServer.ProcReturnString)
Catch ex As Exception
Debug.WriteLine(ex.Message)
Debug.WriteLine(ex.Source)
Debug.WriteLine(ex.ToString)
Debug.WriteLine(ex.StackTrace)
&nb.sp; Finally
vAppServer.Dispose()
End Try
End Sub
.