Error and Interrupt Handling
When you are putting and getting data via the Wolfram Symbolic Transfer Protocol (WSTP) various kinds of errors can occur. Whenever any error occurs, WSTP goes into a completely inactive state, and all WSTP functions you call will return 0 immediately.
|int WSError(WSLINK link)||return a number identifying the current error, or 0 if none has occurred|
|char* WSErrorMessage(WSLINK link)||return a character string describing the current error|
|int WSClearError(WSLINK link)||clear the current error, returning WSTP if possible to an active state|
When you do complicated operations, it is often convenient to check for errors only at the end. If you find that an error occurred, you must then call WSClearError() to activate WSTP again.
After an error, it is common to want to discard the remainder of the packet or expression that you are currently processing. You can do this using WSNewPacket().
In some cases, you may want to set it up so that if an error occurs while you are processing particular data, you can then later go back and reprocess the data in a different way. You can do this by calling WSCreateMark() to create a mark before you first process the data, and then calling WSSeekMark() to seek back to the mark if you need to reprocess the data. You should not forgot to call WSDestroyMark() when you have finally finished with the data—otherwise WSTP will continue to store it.
If you interrupt the Wolfram Language while it is in the middle of executing an external function, it will typically give you the opportunity to try to abort the external function. If you choose to do this, what will happen is that the global variable WSAbort will be set to 1 inside your external program.
WSTP cannot automatically back out of an external function call that has been made. So if you have a function that can take a long time, you should explicitly check WSAbort every so often, returning from the function if you find that the variable has been set.