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

Err.Number and it's relationship to HResult?

P: n/a
I've recently converted some VB 6 code over that used the old non-structured
exception handling. I also have some .NET classes that raise custom
exception classes. When the code was VB6 I used to expose my .NET classes
using COM interop and errors raised from .NET classes were being caught
correctly in VB6. Now that everything is .NET the old non-structured
exception handling is still there in the converted classes. But now the
Err.Number is not reflecting the HResult of the error raised. I wrote a
simple little Windows Application form with 2 buttons to simulate the
problem. Here is the code snippet:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
On Error GoTo ErrHandler
Err.Description = "Test Error"
Err.Raise(-2147215379)
Exit Sub

ErrHandler:
MsgBox(Err.Number & " : " & Err.Description)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Try
Throw New TestException
Catch ex As Exception
MsgBox(Err.Number & " : " & Err.Description)
End Try
End Sub

Private Class TestException
Inherits ApplicationException

Public Sub New()
MyBase.New()
MyBase.HResult = -2147215379
End Sub

Public Overrides ReadOnly Property Message() As String
Get
Return "Test Exception"
End Get
End Property
End Class

If you click Button1 you get the follwoing message:

-2147215379 : Test Error

If you click Button2 you get the following message:

5 : Test Exception

Feb 13 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.