Catching errors while interfacing prolog with C#

Hello,

I am interfacing SWI-Prolog with C# (in Unity) using swiplcs and I would like to catch prolog errors somehow (e.g. using a C# try-catch block) so my program (i.e. the Unity editor) does not crash.

However, using prolog queries inside C# try-cach blocks does not seems to work, my program (Unity) crashes.

Do you know how I could run prolog code safely so my program won’t crash when there is a prolog error somewhere ?

Thanks,
Sylvain

Looking at contrib-swiplcs/SWI-cs-PlQuery.cs at 4cfe15a9721f0e2de214eee71faec5f136034f40 · SWI-Prolog/contrib-swiplcs · GitHub, it looks like it is throwing an exception of type PlException if an error happens in Prolog. Note that misusing the C interface (and indirectly also the C# interface I presume) can easily crash the process.

Also note that the C# interface is really old. I do not know it is still in sync with SWI-Prolog.h

2 Likes

Thanks a lot for the help.
I saw that exceptions were of type PlException but I don’t know how to “catch” them either in Prolog or C# so that my program does not crash. Any idea?
I know that the C# interface is very old, but this is the only I found to interface prolog with C#. Do you know viable alternatives? I head about the Machine Query Interface, but as far as I know, there only is an implementation for Python, implementing it in C# is beyond my skills.