× 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 Thu, 7 Nov 2002, Bartell, Aaron L. (TC) wrote:
>
> I have a question on how you do your errors.  I read your "4.2. improvement
> #2: error handling" from the Socket Tutorial and I am wondering if I should
> create my own RPG/ILE error module that would do what you are describing
> below?  Then if an error occurs all I have to do is pass back a -1 from the
> called module and write an error to the error module.  The calling program
> would then look to the error module for the actual error code and message.
> Is that basically what your FOO_ERROR() is doing?
>

The socket tutorial is explaining how to get the errors from the IBM APIs,
not from my service programs :)

If I have a service prgoram called 'FOOR4' (FOO being the descriptive
name, and R4 indicating RPG IV by my company's naming conventions) then
I generally have procedures like:   foo_open()  foo_dosomething()
foo_close() and foo_error()

I put them all in the same module in the same service program... the idea
being when a programmer sees 'foo_xxx' he knows immediately which service
program and/or source member he will be working with.

My routines, like foo_open, foo_close, etc generally have return values
that either indicate success or error.   Usually, I use 10I 0 for the
return value, and return 0 for success or -1 for error, largely because
I work with C so often.  But sometimes I'll return *Blanks or *NULL or
*OFF for failure... it depends on what I'm returning.

Anyway..   if my routine returns error, the calling program can call
FOO_error() to find out what happened.   Each possible error always has
an error number associated wth it, to make it easier for the calling
program to trap errors as well.   I define constants for each error
number to make the code easier to read.

I know, I know, people are going to reply saying I should use a message
file...  that's a good idea, too...  but I haven't gotten around to
adopting that yet, so I keep doing it this way :)

All this explanation probably is still not as clear as it would
be to look at the actual code... so here's some code...  (I didn't
compile/test this, it's just something I threw together to illustrate the
point)

     h nomain

     **
     ** this /copy member contains the error numbers as constants,
     ** each one beginning with FOO_ERR_xxx as well as the prototypes
     **
      /copy qrpglesrc,foo_h

     D desc_ds         DS                  occurs(100)
     D   fildes                      10I 0
     D   sock                        10I 0
     D   buf                           *
     D   length                      10I 0
     D   errnum                      10I 0
     D   errmsg                      80A

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  translate something (This isn't something real, I just created
      *     it really quick to give you a sample)
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P foo_xlate       B                   export
     D foo_xlate       PI            10I 0
     D   desc                        10I 0 value
     D   from                         1A   const
     d   to                           1A   const

     d p_string        s               *
     D string          s          32766a   based(p_string)

     c     desc          occur     desc_ds

     c                   if        length < 1
     c                   callp     SetError(FOO_ERR_MINLEN: 'string must ' +
     c                                'be at least 1 byte long!')
     c                   return    -1
     c                   endif

     c                   eval      p_string = buf

     c                   for       x = 1 to length
     c                   if        %subst(string:x:1) = from
     c                   eval      %subst(string:x:1) = to
     c                   endif
     c                   endfor

     c                   return    0
     P                 E


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * Used by our 'parent program' to retrieve the last error
      * that occurred for a given descriptor
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P foo_error       B                   export
     D foo_error       PI            80A
     D   desc                        10I 0 value
     D   errnum                      10I 0 options(*nopass)
     c     desc          occur     desc_ds
     c                   if        %parms >= 2
     c                   eval      errnum = desc_errnum
     c                   endif
     c                   return    desc_errmsg
     P                 E

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  Local procedure, used internally to set the error
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P SetError        B
     D SetError        PI
     D   parm_num                    10I 0 value
     D   parm_msg                    80A   const
     c                   eval      errnum = parm_num
     c                   eval      errmsg = parm_msg
     P                 E



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.