By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,673 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,673 IT Pros & Developers. It's quick & easy.

Handling errors from .Net components in VB6 code

P: n/a
Hi all.
I'm writing some .net compoents that are also going to be used from vb6
code. Is there a way for me to distinguish all the different types of
exceptions that the .net code my throw ? My .net component can throw a few
different types of exceptions and I need my vb6 code to take action
differently based on which exception it comes accross.
Can I set the error number somehow on my exception classes? (maybe an
attribute ?)

I'd like my vb6 code to look like:

private Sub MySub()
On Error Goto ErrHandling

dim myDotnetObj as DotNetComponent.Class1
set myDotNetObj = new DotNetcomponent.Class1
myDotNetObj.CallMethod()
Exit Sub

ErrHandling:
Select Case err.Number
Case 123: doSomething1
Case 456: doSomething2
End Select

End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
TJoker .NET,

Check out the section of the .NET framework documentation titled
"HRESULTs and Exceptions", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...exceptions.asp

In it, you will see that certain exceptions map to certain HRESULT error
codes. For your own exceptions, you can override the HResult property to
return an error code for when this exception is marshaled as a COM error
code.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"TJoker .NET" <no****@nonono.no> wrote in message
news:ef****************@TK2MSFTNGP11.phx.gbl...
Hi all.
I'm writing some .net compoents that are also going to be used from vb6
code. Is there a way for me to distinguish all the different types of
exceptions that the .net code my throw ? My .net component can throw a few
different types of exceptions and I need my vb6 code to take action
differently based on which exception it comes accross.
Can I set the error number somehow on my exception classes? (maybe an
attribute ?)

I'd like my vb6 code to look like:

private Sub MySub()
On Error Goto ErrHandling

dim myDotnetObj as DotNetComponent.Class1
set myDotNetObj = new DotNetcomponent.Class1
myDotNetObj.CallMethod()
Exit Sub

ErrHandling:
Select Case err.Number
Case 123: doSomething1
Case 456: doSomething2
End Select

End Sub

Nov 13 '05 #2

P: n/a
Thanks, Nicholas. That helped me a lot.
Another question: Do I have to put Guid attributes on my exception classes ?
I got some strange Automation Error errors on my VB6 code before adding the
Guid attributes, but that could have been a coincidence.

Thanks

TJ

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:uA**************@TK2MSFTNGP11.phx.gbl...
TJoker .NET,

Check out the section of the .NET framework documentation titled
"HRESULTs and Exceptions", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconhresultsexceptions.asp
In it, you will see that certain exceptions map to certain HRESULT error codes. For your own exceptions, you can override the HResult property to
return an error code for when this exception is marshaled as a COM error
code.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"TJoker .NET" <no****@nonono.no> wrote in message
news:ef****************@TK2MSFTNGP11.phx.gbl...
Hi all.
I'm writing some .net compoents that are also going to be used from vb6
code. Is there a way for me to distinguish all the different types of
exceptions that the .net code my throw ? My .net component can throw a few different types of exceptions and I need my vb6 code to take action
differently based on which exception it comes accross.
Can I set the error number somehow on my exception classes? (maybe an
attribute ?)

I'd like my vb6 code to look like:

private Sub MySub()
On Error Goto ErrHandling

dim myDotnetObj as DotNetComponent.Class1
set myDotNetObj = new DotNetcomponent.Class1
myDotNetObj.CallMethod()
Exit Sub

ErrHandling:
Select Case err.Number
Case 123: doSomething1
Case 456: doSomething2
End Select

End Sub


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.