Error Handling

This section provides information on handling errors when using the debugger.


Errors during Application Execution

You can use the debugger to analyze any Natural system error that interrupts program execution. With test mode set to ON (see Switch Test Mode On and Off) or DBGERR set to ON (see the Parameter Reference documentation), the debugger takes control if an error occurs. In this case, a Debug Break window similar to the example below appears:

+------------------- Debug Break -------------------+
! Break by NATURAL error 1316                       !
! at line   60 in program SAGTEST (level 1)         !
!                                                   !
!         G   Go                                    !
!         L   List break                            !
!         M   Debug Main Menu                       !
!         N   Next break command                    !
!         R   Run (set test mode OFF)               !
!         S   Step mode                             !
!         V   Variable maintenance                  !
!                                                   !
! Code .. G                                         !
!                                                   !
! Index not within array structure.                 !
! PF2=Step,PF13=Next,PF14=Go,PF15=Menu,PF17=SkipS   !
+---------------------------------------------------+

Using the List break function, you can display the source code of the program at the position where the last statement was executed. The Natural error number is displayed in the Message column on the right-hand side of the screen and the corresponding source code line is highlighted.

You can then, for example, review the contents of the variables in the program to determine the reason for the error.

Errors during Debugger Execution

If an error is detected while debugging an application, the debugger will terminate and invoke a window with an error message similar to the example shown below:

+------------------ NATURAL Debug Error ---------------------------+
! NATURAL error 3009 has occurred in the NATURAL Debugger.         !
! Last transaction backed out of database 10. Subcode 3            !
!                                                                  !
! Error occurred on level 5 in line 4150 in                        !
! subprogram DBGTEST in library TEST.                              !
! DBGTEST has been loaded from FNAT=(10,932).                      !
! DBGTEST has been cataloged on 2005-04-12 14:43:07.               !
!                                                                  !
! Debugging terminates.                                            !
! Pass this error to application for error processing ? (Y/N): N   !
+------------------------------------------------------------------+

If you confirm this error message with an N (No - this is the default setting), the following happens:

  • The debugger stops debugging and sets the test mode to OFF.

  • The Natural runtime system ignores the error and continues executing the application.

If you confirm this message with a Y (Yes), the following happens:

  • The debugger stops debugging and sets the test mode to OFF.

  • The Natural runtime system reacts to the error and passes it to the application:

    If an ON ERROR statement (see the Statements documentation) is used, the application determines how to proceed after an execution time error occurs. For example, in the case of a NAT3009 where a transaction is backed out of a database, the application can take appropriate action.

    If no ON ERROR statement is used, the Natural runtime system terminates application execution and returns to a Natural command prompt.