2006年10月31日 下午 07:37
I am wondering as to what is the best way to handle exceptions when in a .NET InterOp form and need to throw them. How can I catch these exceptions in the VB6 environment. I am using VS 2005 PRO. and the InterOp ToolKit 1.0. In essence, if an error occurs in my .NET InterOp form, I'd like to Throw it to my VB6 client so that it can catch it and display a messagebox. What is the best practice or does someone have some sample code.
2006年11月7日 下午 07:20版主
There are a variety of ways of handling this. Here's a couple of options...
1) If you have an unhandled error in a winform, you can just let winforms default error handler do it's thing (basically, the user will get an error dialog that says an error has occurred). Unlike VB6, these types of unhandled errors don't crash your app, so the user can just click ok if they want.
2) If you want to handle the error in VB6, you can use use the EventMessager object in VB6 to handle this. See the help or the hybrid example, but basically it works like this:
a) In VB.NET, you trap whatever errors, and use use the my.interoptoolbox.eventmessager.raiseapplictionevent method to raise the event
b) In VB6, you have a withevents variable for the eventmessenger object that you can sync to and then catch any events.
Hope that helps.