MIDRANGE dot COM Mailing List Archive



Home » C400-L » September 2003

RE: error handling on API call



fixed

Dave's recommendation is the one I'd go with as well.

One thing I don't see mentioned by anyone is the use of QSYSINC/H(QUSEC)
include to pull in the system defined Qus_EC_t error code data structure.

If I need exception data (seldom occasion) I define another data structure
on top of the system defined one and use that to pass in to API's that
expect it.

typedef _Packed struct mhErrorCode
 {
  Qus_EC_t               exceptionInfo;
  char                   exceptionData[512];
 } mhErrorCode_t;

so this way you'd set it like:
Qusrobjd(.,.,.,.,.,&errInfo);

mhErrorCode_t errInfo;
errInfo.exceptionInfo.Bytes_Provided = 0;

or if you don't need the exceptionData you don't need to define your own
data structure:

Qus_EC_t errInfo = {0};  /* initialize the entire data structure to zero */
Qusrobjd(.,.,.,.,.,&errInfo);



-----Original Message-----
From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Dave McKenzie
Sent: Wednesday, September 10, 2003 4:24 PM
To: C programming iSeries / AS400
Subject: Re: [C400-L] error handling on API call

The first field in ERC0100_t is called Bytes_Provided in the documentation.

It's an input to the API.  If you set it less than 8, the API sends escape 
messages for errors; if greater than 8, the API returns error info in the 
structure and sets Bytes_Available greater than zero.

I would code it like this:

 typedef struct {
     int Bytes_Provided;
     int Bytes_Available;
     char Exception_ID[7];
     char Reserved;
     char Exception_Data[240];
 } ERRC0100_t;

     ERRC0100_t errInfo;

     /* Verificar si existen las colas */

     memset(&errInfo, 0, sizeof(errInfo));
     errInfo.Bytes_Provided = sizeof(errInfo);

     memcpy(dtaq.lib, "QTEMP     ",
            sizeof(_TE_NAME_T));
     memcpy(dtaq.obj, "OUT_ABGQ  ",
            sizeof(_TE_NAME_T));
     memcpy(objType, "*DTAQ     ",
            sizeof(_TE_NAME_T));
     QUSROBJD(&objInfo, sizeof(objInfo),
              "OBJD0100", &dtaq,
              objType, &errInfo);

     if (errInfo.Bytes_Available > 0) {
       < do error processing >
     }

--Dave


On Wednesday 10 September 2003 12:21 pm, Carlos Kozuszko wrote:
> I want to call API QUSROBJD to check if an object
> exists or not. The API call is working but it sends an
> escape message terminating the program when an error
> occurs (file not found, etc.). How do i prevent this ?
> I want to use the info provided in the error area to
> check for the exception ID, but the program blows
> everytime the object is not found. When i call this
> API from an RPG program the program flow continues
> when an error occurs, how do i simulate this behavior
> ?
>
> Thanks in advance.
>
> Carlos Kozuszko.
>
>
> #include <stdlib.h>
> #include <qsnddtaq.h>
> #include <QUSROBJD.h>
> #include <qtes.h>
>
> typedef struct {
>     int Bytes_Returned;
>     int Bytes_Available;
>     char Exception_ID[7];
>     char Reserved;
>     char Exception_Data[240];
> } ERRC0100_t;
>
> void main() {
>     _TE_NAME_T objType;
>     _TE_OBJLIB_T dtaq;
>     Qus_OBJD0100_t objInfo;
>     ERRC0100_t errInfo;
>
>     /* Verificar si existen las colas */
>     memcpy(dtaq.lib, "QTEMP     ",
>            sizeof(_TE_NAME_T));
>     memcpy(dtaq.obj, "OUT_ABGQ  ",
>            sizeof(_TE_NAME_T));
>     memcpy(objType, "*DTAQ     ",
>            sizeof(_TE_NAME_T));
>     QUSROBJD(&objInfo, sizeof(objInfo),
>              "OBJD0100", &dtaq,
>              objType, &errInfo);
> }
>
>
> ------------
> Internet GRATIS es Yahoo! Conexión
> 4004-1010 desde Buenos Aires. Usuario: yahoo; contraseña: yahoo
> Más ciudades: http://conexion.yahoo.com.ar


_______________________________________________
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.










Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot 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 here. If you have questions about this, please contact