Highlighted
Absent Member.
Absent Member.
885 views

Catch cobol program crashes when called from .NET

[Migrated content. Thread originally posted on 02 March 2011]

Hi, i need to use the API given in the extend framework to call a cobol program from .NET. All it works fine, but if the cobol program crashes the .NET framework does too.

The project we are working on is very critical and we can not permit unexpected crashes of the whole system. Does it exist a way to catch the crash of the cobol program from c# .NET? Catching Exception doesn't work.

As an extreme solution, in C++ it is possible to specify custom handlers for system interrupts; is it possible something similar in the .NET context?
0 Likes
5 Replies
Highlighted
Absent Member.
Absent Member.

RE: Catch cobol program crashes when called from .NET

There is no way the .net framework can catch an exception in the runtime. You may however, try using the CBL_ERROR_PROC to inform the .net framework of an imminent shutdown.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Catch cobol program crashes when called from .NET

Ok, i tried with a combination of CBL_ERROR_PROC, in which i set an error code, and CBL_EXIT_PROC. Unfortunately the only way that i found to make the Extend run time to shut down without causing the .NET runtime to crash as well and making me able to recover the extend error code, is to use the "stop run" directive at the end of the custom EXIT_PROC (actually it is the only instruction). From the Acu doc, it is explicitly unrecommended to use the "stop run" directive into a custom exit procedure, due to undefined behaviour.

The question is, at first, do you know some better way to do what i need with CBL_EXIT_PROC and CBL_ERROR_PROC and if not, which are possible issues due to the undefined behaviour given from the "stop run" usage.

Thank you in advance
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Catch cobol program crashes when called from .NET

Here is a quote from documentation:

[quote]An error procedure must end with an EXIT PROGRAM RETURNING statement which contains an appropriate return value. If the return value is zero, then subsequent error procedures are removed from the queue and are not called.

After all error procedures are called, the exit procedures, if any, are called. Then the run unit is terminated.[/
quote]

Based on this, I don't understand why you would have to do a STOP RUN?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Catch cobol program crashes when called from .NET

I use the stop run into the custom exit procedure, not into the custom error procedure. I use the "exit program returning" in the error procedure to set the error code.

Any instruction other than the "stop run" ("exit program" as specified in acu doc or "goback giving") in the custom exit procedure causes the .NET to crash; if i don't specify a custom exit procedure .NET crashes as well. The only instruction that don't make .NET to crash is "stop run" into a custom exit procedure (CBL_EXIT_PROC).

To make the cobol program crash (as a test) i move a value into a not passed linkage item.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Catch cobol program crashes when called from .NET

Difficult to comment without any example. I suggest you try to come up with a minimal example and send this to Tech support so we can have a look at it.
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.