× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Fri, 21 Apr 2006, Lim Hock-Chai wrote:

My guess would be that there is a service program that contains all the
purch_** procedures.  errMsg variable is a global variable in the
service program.  All purch_** procedures update this field when
encounter error.  purch_error() simply return the errMsg.  Am I close?


You're very close. there's an error message variable that's global to one of the modules in the purch service program. In addition, there's also an error number that corresponds to the message, and that's kept in a global variable as well.

There's a SetError() subprocedure that the various purch_xxx() subprocedures call to set the global variable. That way, they can set it from other modules, if needed. SetError() is exported from the module, but not the service program, so it's not available to anything but modules in the purch service program.

purch_error() returns the error message, and also has an optional parm to return the error number.

In some projects (actually, "purch" happens to be one of them) I take it a step further and create a *MSGF object that contains the error messages that purch uses. The error number corresponds to a msgid, and the message passed to SetERror() is actually just the MSGDTA for the message file. When I call purch_Error() it combines the MSGDTA with the description in the message file. This offers a view advantages:

a) When logging a message to a message queue or job log, I have a unique messageid and text that fits right into the way the rest of the system works.

b) Fatal errors can use *ESCAPE messages, again allowing the caller to monitor by message id, just like operating system messages.

c) If I want to make my program multi-lingual, I can simply use a different message file, since all of the language-specific stuff would be in that.

However, due to the fact that the message file solution adds a lot of extra complexity, I don't use it for every project. For less important projects, I'll just use a global string and global error number like you described.

Since it's all encapsulated into the module, I can always upgrade it to a message file later if I want to.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.