Search code examples
ctcpc89cvi

How can i catch a runtime error in ansi C90


I am using the library Function ConnectToTCPServer. This function times out when the host is not reachable. In that case the application crashes with the following error: "NON-FATAL RUN-TIME ERROR: "MyClient.c", line 93, col 15, thread id 0x000017F0: Library function error (return value == -11 [0xfffffff5]). Timeout error"

The Errorcode 11 is a Timeout error, so this could happen quite often in my application - however the application crashes - i would like to catch this error rather than having my application crash.

How can i catch this runtime error in Ansi C90?

EDIT: Here is a Codesnippet of the current use:

ConnectToTCPServer(&srvHandle, srvPort, srvName, HPMClientCb, answer, timeout);

with

int HPMClientCb(UINT handle, int xType, int errCode, void *transData){
    printf("This was never printed\n");
    return errCode;
}

The Callbackfunction is never called. My Server is not running, so ConnectToTCPServer will timeout. I would suspect that the callback is called - but it never is called.

EDIT 2: The Callback function is actually not called, the Returnvalue of ConnectToTCPServer contains the same error information. I think it might be a bug that ConnectToTCPServer throws this error. I just need to catch it and bin it in C90. Any Ideas?

EDIT 3: I tested the Callbackfunction, on the rare occaision that my server is online the callback function is actually called - this does not help though because the callback is not called when an error occurs.


Solution

  • Looking in NI documentation, I see this:
    "Library error breakpoints -- You can set an option to break program execution whenever a LabWindows/CVI library function returns an error during run time. "

    I would speculate they have a debug option to cause the program to stop on run-time errors, which you need to disable in configuration, in compile time or in run-time.

    My first guess would have been configuration value or compilation flag, but this is the only option I found, which is a run-time option:
    // If debugging is enabled, this function directs LabWindows/CVI not
    // to display a run-time error dialog box when a National Instruments
    // library function reports an error.
    DisableBreakOnLibraryErrors();

    Say if it helped.