Mixing Err.Raise and Exceptions

Hi,

I'm involved in converting a vb6 application to .NET. The application has several business object (activex dll's) and an EXE project which contains the UI. Great I thought at first. So I started converting the business objects to VB.NET, expose them through COM and the UI project can still use them.

So far this has been the case. However I have come across a situation (quite a lot of situations actually) where the business object used to use Err.Raise(<some number>) and then the UI project would use On Error ... to catch these errors, looking at the Err.Number to find out just what exactly went wrong.

I have found that Err.Raise from VB.NET does not marshal very well through COM and in to the UI code. It seems that Err.Raise(n) generally gives the same Err.Number 'on the other side', regardless of n.

From reading the forums it appears that I have to start throwing proper .NET exceptions from the converted code. I have derived my own exception class which in the constructor I set the HResult value to the number that was used in the old Err.Raise statements.

This indeed works, the exceptions thrown in .NET come through to the VB6 UI code in the On Error handler and the Err.Number is HResult that was thrown. Fantastic; the only problem is that the business objects used a lot of Err.Raise so that means a lot of manual changes for me to do.

After all this, my question to the forum is pretty short:

Is this the only way to mix VB.NET error handling and VB6 error handling

Thanks for your help

Graham



Answer this question

Mixing Err.Raise and Exceptions

  • Mixing Err.Raise and Exceptions