Unhandled Errors

As we migrate from a mainframe to Visual COBOL, we are concerned that programs currently aborting with unhandled exceptions will complete without any indication of an error. Here are a couple examples of errors that don’t stop the program with an error message like they do on the mainframe:

 

      Divide by zero

       program-id. Program1 as "Project1.Program1".

       data division.

       working-storage section.

       01 NUMERATOR    PIC 9.

       01 DENOMINATOR  PIC 9.

       01 QUOTIENT     PIC 9.

       procedure division.

           MOVE 1      TO NUMERATOR.

           MOVE ZERO   TO DENOMINATOR.

           COMPUTE QUOTIENT = NUMERATOR / DENOMINATOR.

       end program Program1.

 

       Spaces in a numeric field

       program-id. Program2 as "Project1.Program2".

       data division.

       working-storage section.

       01 GROUP-LEVEL.

          02 NUMERIC-FIELD    PIC 9.

       procedure division.

           MOVE SPACES TO GROUP-LEVEL.

           ADD 1       TO NUMERIC-FIELD.

       end program Program2.

 

 

This example stops the program as we expected the others to:

       program-id. Program3 as "Project1.Program3".

       data division.

       working-storage section.

       01 TBL PIC X OCCURS 3 TIMES INDEXED BY i.

       procedure division.

           SET i TO 4.

           DISPLAY TBL(i) UPON CONSOLE.

       end program Program3.

 

Is there a Visual COBOL configuration that can stop processing on all three of these errors?

  • Verified Answer

    Hi,

    You can use the CHECKDIV"ENTCOBOL" directive so that you get an division by zero error returned. Adding an ON SIZE ERROR would also allow you to handle the error in your code.

    For the spaces in numerics you can use the CHECKNUM directive to get an error for this.

    Regards

    David