|
>Date: Wed, 02 May 2001 22:51:31 +1000 >From: Matthias Oertli <oertlim@s054.aone.net.au> > >The difficulty is that program B needs a different environment to >program A: A slight change in the library list and a modified data >area. > ... >My problem is this: If program B (or the CL) fails for whatever >reason, program A regains control without the environment having been >restored to what it should be which could mean disaster. > >How can I guard against this situation? Matthias, the safest way to ensure that cleanup is always done is to use an ILE cancel handler which will fire if your program crashes or if it gets canceled (sys-req 2 etc). I find it easiest to put the cleanup code in a procedure, and then call the cleanup procedure at the normal end of the routine, and also call the cleanup procedure from the cancel handler. There's an RPG example of enabling and coding a cancel handler in the ILE RPG Programmer's Guide, here: http://publib.boulder.ibm.com:80/cgi-bin/bookmgr/BOOKS/QB3AGY03/3.2.5 If you're not using ILE, change program B to be an ILE program and have it handle the library list stuff and enable the cancel handler, and then call the existing program B, renamed to B2. Others have recommended condition handlers, but they don't handle cancellation due to sys-req-2 or due to using F3 from the debugger, while cancel handlers handle any abnormal termination, due either to a crash or to a cancellation. Handling the cleanup in the caller is also an option, but it's not always the best solution, especially if the program is called from several different callers. In my opinion, cleanup should be handled by a program, not by its callers. (Sorry for the late response - I've been on holiday. Wheee!) Barbara Morris +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.