Conflicts between the associated and FINALLY blocks
- Last Updated: January 16, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
It is possible for a statement that ends a FINALLY block to conflict with a statement that ends the associated block. In these scenarios the general rule is that the last action wins. The following examples illustrate some of these cases:
| Example scenario | Result |
|---|---|
The associated block of a function or non-void method returns a value
(for example, RETURN 5.) and then the
FINALLY block executes a conflicting
RETURN statement (for example,
RETURN 10.). |
Returns 10 from the function or non-void method. |
The associated block raises an error to the outer block or caller and
then the FINALLY block returns a value
(for example, RETURN 10.). |
Returns 10 from the function or non-void method rather than raise the error. |
The associated block returns a value (for example, RETURN 5.) and then the FINALLY block throws an error to the outer
block or caller. |
Raises an error in the outer block or caller; thus the original return value of 5 is lost. |
Best programming practices avoid these conflict scenarios. For example, there
should only be one RETURN statement to return a value
for any code path. If there is a possibility that the FINALLY block can raise ERROR, usually
this is not as important as the original error from the associated block. Therefore, it
is a good practice to use a CATCH block or NO-ERROR in the FINALLY
block to handle it, so the original error propagates up.