Try OpenEdge Now
skip to main content
Error Handling
Handling Errors with CATCH Blocks : Handling errors from built-in ABL methods
 

Handling errors from built-in ABL methods

Traditional error handling treats errors arising from the methods on built-in system handles as warnings. The ERROR condition is not raised, but you can use the NO-ERROR option to trap the error messages in the ERROR-STATUS system handle.
When any CATCH block is present in an associated block, built-in ABL methods raise error. If no CATCH block is present in the associated block that handles ABL system errors, the error is still raised and handled by the implicit or explicit ON ERROR phrase of the associated block.
For example, consider this code:
DO ON ERROR UNDO, THROW:

DEFINE VARIABLE hSocket AS HANDLE NO-UNDO.
    CREATE SOCKET hSocket.
hSocket:CONNECT ("-H localhost -S 3333") /* NO-ERROR */.

CATCH eSysError AS Progress.Lang.SysError:
DISPLAY "CATCH handles connection error on hSocket." SKIP
"Messages..." SKIP
eSysError:GetMessage(1) FORMAT "x(70)" SKIP
eSysError:GetMessage(2) FORMAT "x(70)".
END CATCH.

END. /* DO */

IF ERROR-STATUS:NUM-MESSAGES > 0 THEN
DISPLAY "ERROR-STATUS handle traps connection error on hSocket." SKIP
"Message..." SKIP
ERROR-STATUS:GET-MESSAGE(1) FORMAT "x(70)" SKIP
ERROR-STATUS:GET-MESSAGE(2) FORMAT "x(70)".
When the CONNECT method fails, the CATCH executes and displays two messages. The ERROR-STATUS handle is not used, so the second DISPLAY statement does not execute.
Remove the comments from the NO-ERROR option on the CONNECT( ) method and run the code again. This time the CATCH block does not execute. The ERROR-STATUS system handle traps the error messages, so the second DISPLAY statement executes.