Getting NativeErrorCode from an System.Exception?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paw Pedersen

    Getting NativeErrorCode from an System.Exception?

    When I catch an exception I can see the NativeErrorCode when I'm debugging
    through the code, but how do I get this programatically ?
    I need to check if the exception I catch is with
    nativeErrorCode -1072824317 since this is the only error I'm interestet in.

    Thanks in advance
    Paw


  • Shiva

    #2
    Re: Getting NativeErrorCode from an System.Exceptio n?

    Hi,

    It is a property of Win32Exception. So, you have to catch it explictly and
    access the native error code.

    HTH

    "Paw Pedersen" <news@paws.dk > wrote in message
    news:#TcgbhTeEH A.3632@TK2MSFTN GP11.phx.gbl...
    When I catch an exception I can see the NativeErrorCode when I'm debugging
    through the code, but how do I get this programatically ?
    I need to check if the exception I catch is with
    nativeErrorCode -1072824317 since this is the only error I'm interestet in.

    Thanks in advance
    Paw



    Comment

    • Paw Pedersen

      #3
      Re: Getting NativeErrorCode from an System.Exceptio n?

      I'm not sure how to do that.
      Now I catch it as a System.Messagin g.MessageQueueE xception and there aren't
      any NativeErrorCode property on that. I have tried to catch it as
      Win32Exception, but it doesn't catch the exception then.
      I have also tried to cast the MessageQueueExc eption to a Win32Exception but
      that gives an invalid cast exception.
      Could you give an example?

      Thanks Paw
      "Shiva" <shiva_sm@onlin e.excite.com> wrote in message
      news:eUlrlwTeEH A.3732@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Hi,
      >
      > It is a property of Win32Exception. So, you have to catch it explictly and
      > access the native error code.
      >
      > HTH
      >
      > "Paw Pedersen" <news@paws.dk > wrote in message
      > news:#TcgbhTeEH A.3632@TK2MSFTN GP11.phx.gbl...
      > When I catch an exception I can see the NativeErrorCode when I'm debugging
      > through the code, but how do I get this programatically ?
      > I need to check if the exception I catch is with
      > nativeErrorCode -1072824317 since this is the only error I'm interestet[/color]
      in.[color=blue]
      >
      > Thanks in advance
      > Paw
      >
      >
      >[/color]


      Comment

      • Mattias Sjögren

        #4
        Re: Getting NativeErrorCode from an System.Exceptio n?

        Paw,

        MessageQueueExc eption derived from ExternalExcepti on, which provides
        an ErrorCode property that you can check.



        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org
        http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
        Please reply only to the newsgroup.

        Comment

        • Shiva

          #5
          Re: Getting NativeErrorCode from an System.Exceptio n?

          Ok, for MessageQueue, use the MessageQueueErr orCode property of the
          MessageQueueExc eption.

          The error code -1072824317 is actually MessageQueueErr orCode.QueueNot Found.
          So you can find this specific case as

          if (MessageQueueEx ception.Message QueueErrorCode ==
          MessageQueueErr orCode.QueueNot Found)
          {
          }

          Or if you prefer numeric value comparison,

          if (-1072824317 == (int)MessageQue ueErrorCode.Que ueNotFound)
          {
          }

          "Paw Pedersen" <news@paws.dk > wrote in message
          news:eZASx6TeEH A.2848@TK2MSFTN GP10.phx.gbl...
          I'm not sure how to do that.
          Now I catch it as a System.Messagin g.MessageQueueE xception and there aren't
          any NativeErrorCode property on that. I have tried to catch it as
          Win32Exception, but it doesn't catch the exception then.
          I have also tried to cast the MessageQueueExc eption to a Win32Exception but
          that gives an invalid cast exception.
          Could you give an example?

          Thanks Paw
          "Shiva" <shiva_sm@onlin e.excite.com> wrote in message
          news:eUlrlwTeEH A.3732@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Hi,
          >
          > It is a property of Win32Exception. So, you have to catch it explictly and
          > access the native error code.
          >
          > HTH
          >
          > "Paw Pedersen" <news@paws.dk > wrote in message
          > news:#TcgbhTeEH A.3632@TK2MSFTN GP11.phx.gbl...
          > When I catch an exception I can see the NativeErrorCode when I'm debugging
          > through the code, but how do I get this programatically ?
          > I need to check if the exception I catch is with
          > nativeErrorCode -1072824317 since this is the only error I'm interestet[/color]
          in.[color=blue]
          >
          > Thanks in advance
          > Paw
          >
          >
          >[/color]



          Comment

          • Paw Pedersen

            #6
            Re: Getting NativeErrorCode from an System.Exceptio n?

            Thank you. That work.
            Regards Paw

            "Shiva" <shiva_sm@onlin e.excite.com> wrote in message
            news:#TF6sbUeEH A.1356@TK2MSFTN GP09.phx.gbl...[color=blue]
            > Ok, for MessageQueue, use the MessageQueueErr orCode property of the
            > MessageQueueExc eption.
            >
            > The error code -1072824317 is actually[/color]
            MessageQueueErr orCode.QueueNot Found.[color=blue]
            > So you can find this specific case as
            >
            > if (MessageQueueEx ception.Message QueueErrorCode ==
            > MessageQueueErr orCode.QueueNot Found)
            > {
            > }
            >
            > Or if you prefer numeric value comparison,
            >
            > if (-1072824317 == (int)MessageQue ueErrorCode.Que ueNotFound)
            > {
            > }
            >
            > "Paw Pedersen" <news@paws.dk > wrote in message
            > news:eZASx6TeEH A.2848@TK2MSFTN GP10.phx.gbl...
            > I'm not sure how to do that.
            > Now I catch it as a System.Messagin g.MessageQueueE xception and there[/color]
            aren't[color=blue]
            > any NativeErrorCode property on that. I have tried to catch it as
            > Win32Exception, but it doesn't catch the exception then.
            > I have also tried to cast the MessageQueueExc eption to a Win32Exception[/color]
            but[color=blue]
            > that gives an invalid cast exception.
            > Could you give an example?
            >
            > Thanks Paw
            > "Shiva" <shiva_sm@onlin e.excite.com> wrote in message
            > news:eUlrlwTeEH A.3732@TK2MSFTN GP11.phx.gbl...[color=green]
            > > Hi,
            > >
            > > It is a property of Win32Exception. So, you have to catch it explictly[/color][/color]
            and[color=blue][color=green]
            > > access the native error code.
            > >
            > > HTH
            > >
            > > "Paw Pedersen" <news@paws.dk > wrote in message
            > > news:#TcgbhTeEH A.3632@TK2MSFTN GP11.phx.gbl...
            > > When I catch an exception I can see the NativeErrorCode when I'm[/color][/color]
            debugging[color=blue][color=green]
            > > through the code, but how do I get this programatically ?
            > > I need to check if the exception I catch is with
            > > nativeErrorCode -1072824317 since this is the only error I'm interestet[/color]
            > in.[color=green]
            > >
            > > Thanks in advance
            > > Paw
            > >
            > >
            > >[/color]
            >
            >
            >[/color]


            Comment

            Working...