Accessing the Err.number within a Catch segment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin Hale

    Accessing the Err.number within a Catch segment

    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
    objCardAuthoris ed = .ManualCaptureA uthorisationReq uest(cardDetail s
    Catch ex As Exception
    If Err.Number = (IRPSCOMM_WINSO CK_ERR) Then
    strErrCode = "99999"
    strErrMessage = IRPSCOMM_WINSOC K_DESC
    Return False
    End If
    End Try
    8<--snip----------------------------------------------------------
    Am I flogging a dead horse here? Any learned advice appreciated.
    Colin Hale
  • José Joye

    #2
    Re: Accessing the Err.number within a Catch segment

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

    José
    "Colin Hale" <colinhale@radi usplc.co.uk> wrote in message
    news:a29b3256.0 502170415.69020 952@posting.goo gle.com...[color=blue]
    > 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
    > objCardAuthoris ed = .ManualCaptureA uthorisationReq uest(cardDetail s
    > Catch ex As Exception
    > If Err.Number = (IRPSCOMM_WINSO CK_ERR) Then
    > strErrCode = "99999"
    > strErrMessage = IRPSCOMM_WINSOC K_DESC
    > Return False
    > End If
    > End Try
    > 8<--snip----------------------------------------------------------
    > Am I flogging a dead horse here? Any learned advice appreciated.
    > Colin Hale[/color]


    Comment

    • Nick Hall

      #3
      Re: Accessing the Err.number within a Catch segment


      "Colin Hale" <colinhale@radi usplc.co.uk> wrote in message
      news:a29b3256.0 502170415.69020 952@posting.goo gle.com...[color=blue]
      > 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
      > objCardAuthoris ed = .ManualCaptureA uthorisationReq uest(cardDetail s
      > Catch ex As Exception
      > If Err.Number = (IRPSCOMM_WINSO CK_ERR) Then
      > strErrCode = "99999"
      > strErrMessage = IRPSCOMM_WINSOC K_DESC
      > Return False
      > End If
      > End Try
      > 8<--snip----------------------------------------------------------
      > Am I flogging a dead horse here? Any learned advice appreciated.
      > Colin Hale[/color]

      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
      objCardAuthoris ed = .ManualCaptureA uthorisationReq uest(cardDetail s
      Catch ex As System.Runtime. InteropServices .COMException
      If ex.ErrorCode = (IRPSCOMM_WINSO CK_ERR) Then
      strErrCode = "99999"
      strErrMessage = IRPSCOMM_WINSOC K_DESC
      Return False
      End If
      End Try

      Hope this helps,

      Nick Hall



      Comment

      Working...