handling pywintypes.error exceptions

Roger Upole rupole at hotmail.com
Sat Mar 5 14:41:20 EST 2005


You can capture the extra exception data like this.

try:
...win32net.NetUseAdd(None, 1, {'remote':r'\\foo\bar','local':'X
except pywintypes.error,details:
...err_code=details[0]
...<do something based on the error code>

       Roger

"Lucas Machado" <LMachado1 at gmail.com> wrote in message 
news:1110050058.490815.176610 at f14g2000cwb.googlegroups.com...
> I'm using the win32 api to map samba shares, and I'm having trouble
> handling some exceptions.  In my script there are 2 possible exceptions
> when the script attempts to map a share:
>
>>>> win32net.NetUseAdd(None, 1, {'remote':r'\\foo\bar','local':'X
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> pywintypes.error: (53, 'NetUseAdd', 'The network path was not found.')
>
> This exception occurs when '\\foo\bar' is not an existing share. Also,
> when a drive letter is already in use the following occurs:
>
>>>> win32net.NetUseAdd(None, 1,
> {'remote':r'\\some_server\share','local':'Y:'})
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> pywintypes.error: (85, 'NetUseAdd', 'The local device name is already
> in use.')
>
> I know the exception raised in these cases is "pywintypes.error", but
> how can i differentiate between the two exceptions? Being able to do
> this is critical for my script....
>
> Thanks in advance,
> --Lucas Machado
> 



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----



More information about the Python-list mailing list