Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2003

Tip: Looking for answers? Try searching our database.

Handling errors from .Net components in VB6 code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TJoker .NET - 07 Jul 2003 20:03 GMT
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
Nicholas Paldino [.NET/C# MVP] - 07 Jul 2003 20:07 GMT
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/default.asp?url=/library/en-us/cpguide/html/cp
conhresultsexceptions.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.

Signature

              - Nicholas Paldino [.NET/C# MVP]
              - nicholas.paldino@exisconsulting.com

> Hi all.
> I'm writing some .net compoents that are also going to be used from vb6
[quoted text clipped - 22 lines]
>
> End Sub
TJoker .NET - 07 Jul 2003 20:50 GMT
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

> 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/default.asp?url=/library/en-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
[quoted text clipped - 33 lines]
> >
> > End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.