Skip to Main Content
Due to the recent acquisition by IBM, the Adabas & Natural Ideas Portal does not contain ideas from products ApplinX and EntireX any longer. Please refer to the IBM Ideas Portal for these products from now on (IBMid required). Existing content will be migrated during the next few weeks.
Status Not in Plan
Categories Natural (NAT)
Created by Hezi Shirazi
Created on Aug 21, 2023

on-error-cmd

Hi

as we have on error cmd in a module level, it will be very helpful to have same upon a cmd level (such as in java/c$/python & etc: try/catch)

  • Admin
    Eli Cohen
    Reply
    |
    Dec 29, 2023

    Hello Hezi,

    The try/catch command could be used in Natural by writing the code to be analyzed in

    external subroutine.

    Within the external subroutine the "catch" part is on-error.

    See code sample:

    0010 DEFINE DATA LOCAL

    0020 1 #I (I04)

    0030 1 #N (I04)

    0040 1 #LAST_ERROR (I04)

    0050 1 #MSG (A79)

    0060 END-DEFINE

    0070 #N := 1

    0080 #LAST_ERROR := 0

    0090 F1. FOR #I := 1 TO 99

    0100 PERFORM CALCMULT #I #N #LAST_ERROR

    0110 IF #LAST_ERROR = 0

    0120 THEN

    0130 COMPRESS #I "! = " INTO #MSG LEAVING NO SPACE

    0140 COMPRESS #MSG #N INTO #MSG /* LEAVING NO SPACE

    0150 WRITE #MSG

    0160 ELSE

    0170 WRITE "Overflow occurred - processing terminated"

    0180 ESCAPE BOTTOM (F1.)

    0190 END-IF

    0200 END-FOR /* (F1.)

    0210 END

    0010 DEFINE DATA PARAMETER

    0020 1 #P_I (I4)

    0030 1 #P_N (I4)

    0040 1 #P_LAST_ERROR (I4)

    0050 END-DEFINE

    0060 DEFINE SUBROUTINE CALCMULT

    0070 ON ERROR

    0080 #P_LAST_ERROR := *ERROR

    0090 ESCAPE ROUTINE

    0100 END-ERROR

    0110 #P_N := #P_N * #P_I

    0120 END-SUBROUTINE /* (CALCMULT)

    0130 END