IBM is adding all kinds of new tweaks to RPG with each new release of IBM i
I just noticed a rather neat new function called "ON-EXIT" over at the IBM Developerworks. This is available if you are running IBM i V7.2 or higher:
The ILE RPG compiler is enhanced with a new ON-EXIT opcode which egins the "ON-EXIT" section containing code to be run whenever a procedure ends, either normally or abnormally.
So, if you have code that you always want to run at the end of a procedure you can just put that in the ON-EXIT section. A nice structured way of storing procedure house keeping and/or error catching.
The ON-EXIT operation code begins the ON-EXIT section. The ON-EXIT section contains code that runs every time that the procedure ends, whether it ends normally or abnormally. The ON-EXIT section runs under the following conditions:
The procedure reaches the end of the main part of the procedure.
The procedure reaches a RETURN operation.
The procedure ends with an unhandled exception.
The procedure is canceled, due to the end of the job or subsystem, or due to an exception message being sent to a procedure higher in the call stack.