Highlighted
Absent Member.
Absent Member.
902 views

Unhandled Errors

Jump to solution

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?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: Unhandled Errors

Jump to solution

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

View solution in original post

0 Likes
1 Reply
Highlighted
Absent Member.
Absent Member.

RE: Unhandled Errors

Jump to solution

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

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.