Accessing the Err.number within a Catch segment

C

Colin Hale

Hi,
I've got a legacy ATL component which throws errors using the ATL
Error() function.
I have always handled these errors in VB6 using on error goto, then in
the error handling code I could check err.number to see exactly what
sort of error it was throwing.
I now want to call this old ATL component from vb.net. Can I access
the err.number value from my catch code eg..
8<--snip----------------------------------------------------------
Try
objCardAuthorised = .ManualCaptureAuthorisationRequest(cardDetails
Catch ex As Exception
If Err.Number = (IRPSCOMM_WINSOCK_ERR) Then
strErrCode = "99999"
strErrMessage = IRPSCOMM_WINSOCK_DESC
Return False
End If
End Try
8<--snip----------------------------------------------------------
Am I flogging a dead horse here? Any learned advice appreciated.
Colin Hale
 
J

José Joye

You can catch an instance of COMException instead of the general Exception
class

José
 
N

Nick Hall

Colin Hale said:
Hi,
I've got a legacy ATL component which throws errors using the ATL
Error() function.
I have always handled these errors in VB6 using on error goto, then in
the error handling code I could check err.number to see exactly what
sort of error it was throwing.
I now want to call this old ATL component from vb.net. Can I access
the err.number value from my catch code eg..
8<--snip----------------------------------------------------------
Try
objCardAuthorised = .ManualCaptureAuthorisationRequest(cardDetails
Catch ex As Exception
If Err.Number = (IRPSCOMM_WINSOCK_ERR) Then
strErrCode = "99999"
strErrMessage = IRPSCOMM_WINSOCK_DESC
Return False
End If
End Try
8<--snip----------------------------------------------------------
Am I flogging a dead horse here? Any learned advice appreciated.
Colin Hale

I *think* such errors will be exposed as a
System.Runtime.InteropServices.COMException to your calling code.
COMException exposes an error code property which should contain the
requisite value. So your code would become: -

Try
objCardAuthorised = .ManualCaptureAuthorisationRequest(cardDetails
Catch ex As System.Runtime.InteropServices.COMException
If ex.ErrorCode = (IRPSCOMM_WINSOCK_ERR) Then
strErrCode = "99999"
strErrMessage = IRPSCOMM_WINSOCK_DESC
Return False
End If
End Try

Hope this helps,

Nick Hall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top