There is an unmanaged library written in Delphi, and a graphical shell written in C #. It is necessary to make so that the library on Delphi could throw an exception which could be processed at the level C #. Now the Delphi library throws a custom exception, but a .NET comes with a SEHException , which the try/catch does not act on. What should I throw on Delphi to make it work?

  • And try { /*код*/ } catch {} (exactly, and not catch (Exception) ) doesn't help? How does interop work for you? - VladD
  • Through LoadLibrary desired function is loaded (the user can select it), then Marshal.GetDelegateForFunctionPointer and run. Block catch and so on without a specific exception. - Modus
  • @Modus: Do you just need to catch, or do you want to get a specific native exception type? The second, I fear, is impossible :( - VladD
  • Yes, at least catch. The problem is that try-catch does not work - Modus
  • @Modus: Ah, even so? Normal native exceptions should wrap around in a SEHException and be caught along with all the others. Try this , maybe the problem is here. - VladD

1 answer 1

Exceptions in Delphi and exceptions in .NET are two big differences, they are not compatible at all. The only way I see it is to modify your Delphi DLL so that the methods return error codes instead of exceptions (just like WinAPI does) and then write a .NET wrapper that will translate these error codes into exceptions.

There is another option for extremes - rewrite your DLL-ku to Delphi in the COM library, and zayuzat it in .NET via COM Interop. It seems to me that exceptions should be caught there all, but I did not try it myself.

But I would choose the first option, cheap and cheerful.