MSMQ MessageQueueException

Topics: Exception Handling Application Block
Nov 20, 2011 at 4:24 PM

Hi all,

I am new to the ELIB and have been testing some simple apps.
For instance, I have a small MSMQ test app which will try to send messages, read list of private queues etc. for most failures a MessageQueueException is thrown. However, to get the details of the exception, the MessageQueueErrorCode property needs to be check.


- MessageQueueErrorCode.IOTimeout
- MessageQueueErrorCode.AccessDenied


I am trying to use ELIB, and in my exception type, I have MessageQueueException. However, I now want to replace the message with a user friendly message, but the handler doesnt seem to allow me to check the actual MessageQueueErrorCode to be able to throw the actual error.

I was hoping that I can have all my checks in the policy and then plug it in to all the functions.



Thanks for you help

Nov 20, 2011 at 11:10 PM

There is no out of the box functionality to handle MessageQueueException.  As you note, the reason why it's not a good fit with the ExceptionHandler model is that MessageQueueException is basically a wrapper for all MSMQ errors with the specific error being represented by an enumeration.

For you situation, the best approach is to create a custom Exception Handler.  I.e. create a class called MesssageQueueExceptionHandler that implements IExceptionHandler and contains the message mapping features you want.  Once you have a custom handler then you can use that in any policies to handle MesssageQueueException. 

Randy Levy
Enterprise Library support engineer

Nov 21, 2011 at 6:49 AM

Thanks Randy. Will have a go at this