ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

callp(E) ANYTHING in call stack

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • callp(E) ANYTHING in call stack

    callp(e) pgma
    calls pgmb
    calls pgmc

    If pgma encounters an unrecoverable error, i can catch it... however, if pgmc encounters an unrecoverable error, how can i check/catch that at the point I call pgmA, without falling into a MSGW status?


  • #2
    Use a Monitor Group

    Monitor
    //Your Program Code
    On-Error
    //Handle any error
    EndMon;

    Comment


    • #3
      so I tried...

      Monitor
      callp pgma
      On-Error
      logerror();
      EndMon;


      pgma calls pgmb and pgmb calls pgmc.

      a date timestamp error occurs in pgmc - the monitor does not catch that error and the pgm bombs with msgw on pgmc.

      how can i prevent this?

      Here is what the actual call stack looks like... (pgmA is BHFPBRATE and pgmC is BHFEIINT)
      (sorry - i changed the font to courier new and it formatted fine but lost formatting when i hit save - tried to reformat but it wouldn't)

      my guess it is the control boundary on pgmB??

      Display Call Stack
      System: S10B5181
      Job: QZRCSRVS User: QUSER Number: 227794
      Thread: 00000006

      ------Activation Group------ Control
      Type Program Name Number Boundary
      QZRCSRVS QSYS *DFTACTGRP 0000000000000001 Yes
      QZRCSRVS QSYS *DFTACTGRP 0000000000000001 No
      QZRCSRVS QSYS *DFTACTGRP 0000000000000001 No
      WS00000000 DVBDCOBJ *NEW 000000000000001A Yes
      WS00000000 DVBDCOBJ *NEW 000000000000001A No
      WS00000000 DVBDCOBJ *NEW 000000000000001A No
      BHFPBRATE DVBDCOBJ *NEW 000000000000001A No
      BHFPBRATE DVBDCOBJ *NEW 000000000000001A No
      BHFWSINT DVBDCOBJ *DFTACTGRP 0000000000000002 Yes
      BHFWSINT DVBDCOBJ *DFTACTGRP 0000000000000002 No
      BHFEIINT DVBDCOBJ *DFTACTGRP 0000000000000002 No
      BHFEIINT DVBDCOBJ *DFTACTGRP 0000000000000002 No
      QRNXUTIL QSYS *DFTACTGRP 0000000000000002 No
      More...
      F3=Exit F5=Refresh F11=Display statements F12=Cancel F16=Job menu
      F17=Top F18=Bottom F22=Display entire field
      Last edited by jayvaughn; February 7, 2017, 06:59 AM.

      Comment


      • #4
        Jay, pgmc has to monitor for the error. Pgmb can monitor for a cancellation of pgmc, but it cannot monitor for errors within pgmc.

        Comment


        • #5
          That's what I concluded also, in my testing. I wonder what/why the rule is to restrict that downline monitoring?

          Comment


          • #6
            Jay,

            You probably want to look into the ILE concept of "Control Boundaries". This is what determines whether MONITOR can be used to catch an error that occurs within a called routine (or not.)

            The TL;DR version is: Errors are propagated back down the call stack (and may be caught by parent-level monitoring) until the activation group changes. If the activation group changes in the call stack (without a monitor catching the error) the propagation stops, and an error is displayed to the user.

            Comment


            • #7
              Originally posted by Scott Klement View Post
              Jay,

              You probably want to look into the ILE concept of "Control Boundaries". This is what determines whether MONITOR can be used to catch an error that occurs within a called routine (or not.)

              The TL;DR version is: Errors are propagated back down the call stack (and may be caught by parent-level monitoring) until the activation group changes. If the activation group changes in the call stack (without a monitor catching the error) the propagation stops, and an error is displayed to the user.
              thank you Scott - will do that.
              Last edited by jayvaughn; February 7, 2017, 01:14 PM. Reason: to not sound illiterate

              Comment


              • #8
                RPG only shows an inquiry message if the program has a cycle-main. So if you change PGMB to have a linear-main, PGMB will just crash without showing an inquiry message.

                Comment


                • #9
                  Originally posted by Barbara Morris View Post
                  RPG only shows an inquiry message if the program has a cycle-main. So if you change PGMB to have a linear-main, PGMB will just crash without showing an inquiry message.
                  a linear main being a *module (with nomain in h-spec)?

                  Comment


                  • #10
                    Can you modify PGMC (or have the vendor do it) or fix the rogue program writing bad data? Seems like you are going for the pound of cure instead of the ounce of prevention. Regards.

                    Comment


                    • #11
                      CRinger400 - we have done that and THAT issue is resolved. However this is a webservice stream that leaves the front end hanging. so that pound of cure is intended to address any accumulation of ounces down the road and not leave the front end user staring at the beautiful gui screen we developed. haha. Ultimately sounds like what we need to do in this particular case is put monitors at each new control boundary in the stream.

                      Comment


                      • #12
                        Originally posted by jayvaughn View Post

                        a linear main being a *module (with nomain in h-spec)?
                        A linear main program is a *pgm object with MAIN in the H (CTL-OPT) specs.

                        Comment


                        • #13
                          A linear main procedure is like an ordinary subprocedure except that it is designated as the main procedure for the program by using the MAIN keyword in the H specs, as Ted said.

                          Here's an example of a program with a linear main. Notice that the main procedure ends when it gets to the end of the calculations. *INLR is meaningless, and RETURN is not needed to end the procedure. An excerpt from my joblog is below, showing that it just crashes when it gets an error, without showing an inquiry message.

                          Code:
                          ctl-opt main(mypgm);
                          
                          dcl-proc mypgm;
                             dcl-pi *n extpgm;
                                name char(10) const;
                             end-pi;
                             dcl-s num int(10);
                          
                             doGreeting (name);
                          
                             if name = '?';
                                num = 5 / num; // divide by zero
                             endif;
                          end-proc;
                          
                          dcl-proc doGreeting;
                             dcl-pi *n;
                                theName char(10) const;
                             end-pi;
                          
                             dsply ('Hello, ' + theName);
                          end-proc;
                          Code:
                          4 > call junkpgm 'Barbara'                                            
                              DSPLY  Hello, Barbara                                             
                          4 > call junkpgm '?'                                                  
                              DSPLY  Hello, ?                                                   
                              Attempt made to divide by zero for fixed point operation.         
                              Application error.  MCH1211 unmonitored by JUNKPGM at statement   
                                0000000010, instruction X'0000'.

                          Comment


                          • #14
                            Hey Barbara, thanks for setting up that example to explain what Ted was referring to (thanks Ted) - so sounds like in my case, if i had main(BHFEIINT) in the hspec of BHFEIINT (pgmC in my example), then no inquiry message would be invoked if pgmC crashed. Am I interpreting this correctly? Is that all it would need? Is a dump produced if it errors/exits this way?

                            Comment


                            • #15
                              Originally posted by jayvaughn View Post
                              Hey Barbara, thanks for setting up that example to explain what Ted was referring to (thanks Ted) - so sounds like in my case, if i had main(BHFEIINT) in the hspec of BHFEIINT (pgmC in my example), then no inquiry message would be invoked if pgmC crashed. Am I interpreting this correctly? Is that all it would need? Is a dump produced if it errors/exits this way?
                              No, I think you need to make BHFWSINT a linear main program. I think that's the one that's getting the inquiry message due to the failed call to C, right? Inquiry messages are issued for RPG programs if the cycle-main program is DFTACTGRP(*YES) or if it is on a control boundary. Looking at your stack, PGMB is on a control boundary, so that's the one you have to prevent getting an inquiry message.

                              From your program stack listing, I assume BHFEIINT is ACTGRP(*CALLER), so any unhandled error messages will percolate to its caller.

                              But since getting inquiry messages is Not A Good Thing in your environment, it would probably be a good idea to prevent any RPG program from issuing an inquiry message if it crashes, either by avoiding the RPG cycle, and/or by adding MONITORs. MONITOR is a good way to handle this, but then you to have some way of communicating errors back to your caller.
                              Code:
                              [FONT=courier new]Program             Actgrp      Number            Control Boundary
                              QZRCSRVS   QSYS     *DFTACTGRP  0000000000000001  Yes
                              QZRCSRVS   QSYS     *DFTACTGRP  0000000000000001  No
                              QZRCSRVS   QSYS     *DFTACTGRP  0000000000000001  No
                              WS00000000 DVBDCOBJ *NEW        000000000000001A  Yes      PGM0 (program-entry-procedure)
                              WS00000000 DVBDCOBJ *NEW        000000000000001A  No            (main procedure)
                              WS00000000 DVBDCOBJ *NEW        000000000000001A  No            (some other procedure)
                              BHFPBRATE  DVBDCOBJ *NEW        000000000000001A  No       PGMA (program-entry-procedure)
                              BHFPBRATE  DVBDCOBJ *NEW        000000000000001A  No            (main procedure)
                              [B]BHFWSINT   DVBDCOBJ *DFTACTGRP  0000000000000002  [COLOR=#FF0000]Yes[/COLOR]      PGMB (program-entry-procedure)[/B]
                              BHFWSINT   DVBDCOBJ *DFTACTGRP  0000000000000002  No            (main procedure)
                              BHFEIINT   DVBDCOBJ *DFTACTGRP  0000000000000002  No       PGMC (program-entry-procedure)
                              BHFEIINT   DVBDCOBJ *DFTACTGRP  0000000000000002  No            (main procedure)
                              QRNXUTIL   QSYS     *DFTACTGRP  0000000000000002  No[/FONT]

                              Comment

                              Working...
                              X