Handling errors
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
The RUN STORED-PROC statement supports the NO-ERROR
option. and these examples show how to trap errors within a procedure using the
NO-ERROR option.
How to trap errors within a stored procedure using NO-ERROR option
|
Trapping errors within a procedure using NO-ERROR option
This example assumes that you used the customer table from the demo
database to create sp_write_cust procedure that inserts two records into
the customer table:
|
In this example, sp_write_cust procedure execution causes a unique index
error because it tries to insert two values for cust_num, a primary key of
the customer table. Then, the unique index error is handled by
ERROR-STATUS handle in the IF block.
|
The DataServer internally closes the stored procedure handle when the stored procedure
fails to execute. You must ensure that the error handling code block immediately follows the
RUN STORED-PROCEDURE call so that errors captured using
NO-ERROR are not lost by the execution of another statement. Including
the CLOSE STORED-PROCEDURE statement in the error handling block causes a
run-time error because closure is implicit. Only if the procedure is run successfully will a
procedure handle be established, and only then do you need to execute CLOSE
STORED-PROCEDURE on the open handle.
The error in this example can also be handled using a CATCH end block in
the procedure block that performs the RUN STORED-PROC statement.
Trapping errors within a procedure using CATCH option
This example shows how to trap errors within a procedure using a CATCH end
block.
|
For more information on the NO-ERROR option, CATCH statement or CATCH end block, in OpenEdge ABL, see Develop ABL Applications.
Trapping errors when using LOAD-RESULT-INTO
By properly positioning the NO-ERROR in the RUN
statement, error information can also be retrieved from attempted SQL execution at the data
source when using LOAD-RESULT-INTO. shows how errors are trapped after
LOAD-RESULT-INTO stored procedure execution.
|