Getting NativeErrorCode from an System.Exception?

  • Thread starter Thread starter Paw Pedersen
  • Start date Start date
P

Paw Pedersen

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
 
Hi,

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

HTH

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
 
I'm not sure how to do that.
Now I catch it as a System.Messaging.MessageQueueException 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 MessageQueueException to a Win32Exception but
that gives an invalid cast exception.
Could you give an example?

Thanks Paw
 
Paw,

MessageQueueException derived from ExternalException, which provides
an ErrorCode property that you can check.



Mattias
 
Ok, for MessageQueue, use the MessageQueueErrorCode property of the
MessageQueueException.

The error code -1072824317 is actually MessageQueueErrorCode.QueueNotFound.
So you can find this specific case as

if (MessageQueueException.MessageQueueErrorCode ==
MessageQueueErrorCode.QueueNotFound)
{
}

Or if you prefer numeric value comparison,

if (-1072824317 == (int)MessageQueueErrorCode.QueueNotFound)
{
}

I'm not sure how to do that.
Now I catch it as a System.Messaging.MessageQueueException 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 MessageQueueException to a Win32Exception but
that gives an invalid cast exception.
Could you give an example?

Thanks Paw
 
Thank you. That work.
Regards Paw

Shiva said:
Ok, for MessageQueue, use the MessageQueueErrorCode property of the
MessageQueueException.

The error code -1072824317 is actually MessageQueueErrorCode.QueueNotFound.
So you can find this specific case as

if (MessageQueueException.MessageQueueErrorCode ==
MessageQueueErrorCode.QueueNotFound)
{
}

Or if you prefer numeric value comparison,

if (-1072824317 == (int)MessageQueueErrorCode.QueueNotFound)
{
}

I'm not sure how to do that.
Now I catch it as a System.Messaging.MessageQueueException 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 MessageQueueException to a Win32Exception but
that gives an invalid cast exception.
Could you give an example?

Thanks Paw
 
Back
Top