xsharp.eu • Error handling strucErrInfo
Page 1 of 1

Error handling strucErrInfo

Posted: Thu Apr 28, 2022 6:07 am
by JohnBonnett88
I am working on the conversion of a large VO system to X#. I did not create it and am a newbie to VO, but have much experience in other languages, including in the .NET environment.

I seem to be able to sort most things with the help files and the other X# support, but I am a bit stalled with this one, even after digging around for a while. The following code is from an error reporting routine in our app. It gets passed an error in oError and, the way I read it, it checks to see that oError is in fact an error object, if not it generates an error about that.

IF !(IsInstanceOf(oError, #ERROR))
ClearstrucErrInfo()
strucErrInfo.dwGenCode := EG_WRONGCLASS
strucErrInfo.dwSeverity := ES_ERROR
strucErrInfo.symFuncSym := #DefError
strucErrInfo.pszArg := AsPsz(oError)
strucErrInfo.dwArgNum := 1
strucErrInfo.lCanDefault := .T.
oError := ErrorBuild(@strucErrInfo)
ENDIF

The compiler complains that it does not know two identifiers strucErrInfo and ClearstrucErrInfo. From my research they seem to be from a global error handling feature in VO. It may be that I just need the correct reference to an assembly, but have not found that. It may need to be redone in some newer way.

Can anyone direct me to a solution?

Incidentally I would like to complement the X# team on what they have produced. It is a fine piece of work.

Best Regards,
John Bonnett

Error handling strucErrInfo

Posted: Thu Apr 28, 2022 7:42 am
by robert
John.
First: thanks for the compliments. This is really appreciated.
W.r.t. your question:
The Visual Objects runtime is not really object oriented itself. Most of the functionality in the runtime is exposed through functions, such as the various RDD related functions.
When an error occurs in the runtime then these functions do not generate an Error object but they return FALSE and store the description of the error in a structure inside the runtime and then a function is called that checks to see if a default error handler installed. When there is such an error handler, then a reference to the structure is passed as argument in a call to this function.

So the error handler code in VO can be called with either an Error object or with a pointer to this error structure.
In X# we have a different situation: all errors are either a System.Exception object or a XSharp.Error object (which is a subclass of System.Exception).
We have added similar function to the X# runtime as ErrorBuild() but that function now expects a System.Exception parameter and will create a Error object from that parameter.

And when an error occurs in the X# runtime in a function that is expected to return errors with a logical return value(like the RDD functions), then the "real error" (exception) is stored in the RuntimeState:LastRDDError property.

So if you want to emulate this behavior you should create a System.Exception object and fill it with the values that you want and call ErrorBuild and pass the exception.
You can also directly create a XSharp.Error object and pass that to ErrorBuild (since error inherits from Exception)

Robert

Error handling strucErrInfo

Posted: Fri Apr 29, 2022 2:53 am
by JohnBonnett88
Robert,
Thanks for your comprehensive reply. I had discovered some of those details while looking through the help and other resources but You have answered my question about what I should do to fix the code.

While using the help for the X# runtime, I wondered what the "View Code" button did, so I clicked it. It goes straight to the X# code of the runtime item of interest on GitHub. That is very helpful and is a feature made possible by the code being open source.

Thanks again.
John

Error handling strucErrInfo

Posted: Fri Apr 29, 2022 1:15 pm
by ic2
JohnBonnett88 wrote: While using the help for the X# runtime, I wondered what the "View Code" button did, so I clicked it. It goes straight to the X# code of the runtime item of interest on GitHub. That is very helpful and is a feature made possible by the code being open source.
I didn't that either. Very interesting indeed!

Dick