tags:

views:

46

answers:

1

I am calling a .Net assembly from a Delphi project using COM interop.

Can I catch .Net exceptions in Delphi thrown by the assembly?

+3  A: 

COM does not work with .NET exceptions but with HRESULT values. So there is no way you can catch .NET exceptions at Delphi side. You just receive a HRESULT with an error value. If you are lucky you will get an HRESULT with a specific error value so you know what has gone wrong, if you're unlucky, you will get some generic HRESULT value.

The_Fox
hm, if i call procedure, it will return nothing, but it can throw exception, so i can not do anything?
eba
Every COM method returns an HRESULT value. I don't know how COM interop at the .NET side is handled, but I guess that even when a procedure goes wrong, it will return an HRESULT with an error value.
The_Fox
thx, i;ll try to figure it
eba
@eba: perhaps you are referring to Delphi's Safecall. The safecall calling convention encapsulates COM error handling, When calling a safecall function from Delphi code, Delphi automatically checks the returned HRESULT and raises an exception if necessary.
Remko