[python-win32] MSMQ - cannot catch COM_ERROR with"pythoncom.com_error"

Tim Golden mail at timgolden.me.uk
Tue Jul 22 17:20:32 CEST 2008


Lynton Grice wrote:
> Please help me ;-) I know how to push / pop messages off of a MSMQ, also how
> to create a queue etc.....but my problem is I cannot seen to catch the
> "com_error" when I try create a MSMQ that already exists ;-( The basic code
> is as follows:
> 
> import win32com.client
> import pythoncom
> import os
> 
> try:  
>     queue_info = win32com.client.Dispatch("MSMQ.MSMQQueueInfo")  
>     computer_name = os.getenv('COMPUTERNAME')
>     format_name = "direct=os:" + computer_name + "\\private$\\test3"
> 
>     queue_info.FormatName=format_name        
>     queue=queue_info.Open(2,0)  "Dies here obviously as queue does not exist
> except pythoncom.com_error:
>     #Queue does not exist...create queue....    
>     queue_info.PathName = ".\\private$\\test3"
>     queue_info.Label = "New Queue"
>     queue_info.Create()
> 
> I get an Exception raised in WingIDE that says something like
> "com_error......the queue does not exist or you do not have sufficient
> permissions etc" - something like that.....

I can't see anything obvious (aside from the
possible dangers inherent in assuming that
*any* com_error means the queue doesnt' exist).
I assume that the -- "Dies here... -- isn't in the
original code?

Does the same thing happen if you run in the
standard interpreter? (Don't know if WingIDE
does anything fancy to intercept exceptions).

If the same does happen in the interpreter, can
you use the traceback module / sys.exc_info to
determine exactly what exception is raised and
how it relates to pythoncom.com_error?

TJG


More information about the python-win32 mailing list