Try OpenEdge Now
skip to main content
Error Handling
Traditional Error Handling : Raising the ERROR condition
 

Raising the ERROR condition

You have already seen that you can raise ERROR with the RETURN ERROR option of both the ON ERROR phrase and the UNDO statement. The RETURN statement with the ERROR option is the third way to raise ERROR.
In general, the RETURN statement allows you to exit a block immediately. Immediately means that execution of the block halts with the RETURN statement and returns to the calling block without consideration to intervening blocks.
The statement leaves the local or remote procedure or user-defined function block, trigger block, database trigger block, the method block of a class, the class constructor block, or the property accessor block, and returns to the calling procedure, user-defined function, method, constructor, or property accessor. If there is no caller, RETURN returns to the tool that invoked the routine. This is the syntax for the RETURN statement:

Syntax

RETURN
    [return-value|
       ERROR [return-value |error-object-expression]|
       NO-APPLY ]
return-value
The value that RETURN returns to the caller with or without the ERROR condition.
ERROR
Causes an ERROR condition in the calling block. This can cause the ERROR condition to be raised for the following statements in the caller:
*The RUN statement for a procedure
*Any statement that invokes a method of a class
*Any statement that invokes the NEW or DYNAMIC-NEW function to instantiate a class (invoking the specified constructor and all other constructors for the class hierarchy)
*Any statement that accesses a property defined with property accessors
You can use the ERROR option in a procedure, database trigger block, class-based method, constructor, property accessor method. However, you cannot use the ERROR option in a user-interface trigger block or destructor to raise ERROR outside of the trigger block. Any values that are set for OUTPUT or INPUT-OUTPUT parameters before the RETURN ERROR executes are not returned to the caller.
The following table shows how to access return-value in the caller in various cases:
In this case . . .
How to retrieve the return value in the caller . . .
The return-value is specified without the ERROR option in a procedure or trigger block.
Access the RETURN-VALUE function.
The return-value is specified for a non-VOID method or user-defined function without the ERROR option.
Access the method or function return value by referencing the function or method call in an expression, similar to referencing a variable.
The return-value is specified with the ERROR option.
Access the RETURN-VALUE function. For structured error handling, you can also access the ReturnValue property of the error object.
error-object-expression (structured error handling)
This feature is documented in UsingABL Error Classes
NO-APPLY
Suppresses the default behavior for the current user-interface event. You can use the NO-APPLY option in a user-interface trigger block to suppress that behavior. For example, the default behavior for a character code key press in a fill-in field is to echo the character in the field. If you execute RETURN NO-APPLY in a trigger, this behavior is not performed and NO-APPLY returns without setting a return-value.
* User defined functions