Along with the cobsetjmp() function, this function provides the capability of a non-local GO TO, for use in error or exception handling.

This function is supported for native COBOL only.


#include "cobsetjmp.h"

void coblongjmp(struct cobjmp_buf *buf);


buf A buffer in which the current execution environment is saved.


The cobsetjmp() function saves the environment of the current COBOL program and C function in the buffer pointed to by buf. It calls the C library function setjmp(), which immediately returns a value of 0.

A subsequent call to coblongjmp() either from elsewhere in the C function that called cobsetjmp(), or from one of its C or COBOL subprograms, causes execution to be resumed at the point immediately after the call to cobsetjmp().

After calling coblongjmp(), cobsetjmp() returns a non-zero value, thus enabling the value to be tested after the cobsetjmp() call.

The following restrictions apply when using the coblongjmp() and cobsetjmp() functions:

  • cobsetjmp() and coblongjmp() can be called from a C program only; they cannot be called from COBOL.
  • coblongjmp() must be called from the same or from a lower level in the CALL/PERFORM hierarchy of control flow as cobsetjmp(). In the intervening time, control must not have been returned to a higher level. Specifically, control must not have been returned from the C function that called cobsetjmp().
  • If coblongjmp() returns control to a different call level than that used by cobsetjmp(), programs exited by this mechanism appear to have been exited normally and can be called again later in the program's run.
  • coblongjmp() cannot be used if a CHAIN has been made since cobsetjmp() was last called.
  • coblongjmp() cannot be used in an error procedure, exit procedure or asynchronous signal handler.
  • coblongjmp() must be called from the same thread as the corresponding call to cobsetjmp().
  • coblongjmp() does not reset any thread synchronization objects that have been initialized or changed since the corresponding cobsetjmp(). These may need be reset to prevent potential thread deadlocks.
  • coblongjmp() does not free any memory allocated since the corresponding cobsetjmp(), which could lead to memory leaks.

Equivalent COBOL Syntax:



The following shows how to use the coblongjmp() and cobsetjmp() functions:

    struct cobjmp_buf buf;

    if (cobsetjmp(&buf) != 0)
        cobprintf("Returned from coblongjmp\n");
    /* Valid code here - for example can call COBOL */