473,549 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

handling pywintypes.erro r exceptions

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.NetUse Add(None, 1, {'remote':r'\\f oo\bar','local' :'X Traceback (most recent call last):
File "<stdin>", line 1, in ?
pywintypes.erro r: (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.NetUse Add(None, 1,

{'remote':r'\\s ome_server\shar e','local':'Y:' })
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pywintypes.erro r: (85, 'NetUseAdd', 'The local device name is already
in use.')

I know the exception raised in these cases is "pywintypes.err or", but
how can i differentiate between the two exceptions? Being able to do
this is critical for my script....

Thanks in advance,
--Lucas Machado

Jul 18 '05 #1
1 8710
You can capture the extra exception data like this.

try:
....win32net.Ne tUseAdd(None, 1, {'remote':r'\\f oo\bar','local' :'X
except pywintypes.erro r,details:
....err_code=de tails[0]
....<do something based on the error code>

Roger

"Lucas Machado" <LM*******@gmai l.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.NetUse Add(None, 1, {'remote':r'\\f oo\bar','local' :'X Traceback (most recent call last):
File "<stdin>", line 1, in ?
pywintypes.erro r: (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.NetUse Add(None, 1,

{'remote':r'\\s ome_server\shar e','local':'Y:' })
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pywintypes.erro r: (85, 'NetUseAdd', 'The local device name is already
in use.')

I know the exception raised in these cases is "pywintypes.err or", 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 =----
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1167
by: Steffan Surdek | last post by:
Hi All! We are interfacing an ASP page with a COM object. In the COM object, if there is a condition that makes it not possible to perform the requested action, an exception is raised that can be caught by the calling application. When an exception is raised by the COM object during the processing in the ASP page, the processing seems...
4
1887
by: Ken Fine | last post by:
No joy on Macromedia's boards after a few days; maybe someone can help me here. I got an excellent string handling function off of planet-source-code.com that converts text strings to proper case, i.e. "the REMAINS of the DAY" is converted to "The Remains Of The Day". This function is particularly good in that it handles certain...
1
4765
by: Bill S. | last post by:
Hi, I a stored procedure that inserts a record into a table as below. The insert works OK, but if the insert violates a unique indewx constraint on one of the columns, the proc terminates immediately, and does NOT execute the 'if @@ERROR <> 0' statement.
59
4378
by: kk_oop | last post by:
Hi. I wanted to use exceptions to handle error conditions in my code. I think doing that is useful, as it helps to separate "go" paths from error paths. However, a coding guideline has been presented that says "Use conventional error-handling techniques rather than exception handling for straightforward local error processing in which a...
3
6368
by: vj | last post by:
Please let me know how can i handle any kind of error conditions with a single (condition and continue handler). I need to catch any kind of exception thrown in the procedure with a single ( declare condition and a declare continue handler) Thanks in advance. Vijay
0
3320
by: Janjan | last post by:
I want to catch any soapexception error by these method. My question is Does creating an instance from assembly name can retrieve exception errors from UI? I have read documents on handling soapexception errors but i want to make it general on this. Is this procedure posible? Because it returns an error message of "HRESULT has returned from a...
3
3390
by: Robert Rotstein | last post by:
It appears that exception handling at the top-most level of a C# program, in the static void Main() method, differs depending on whether the program is run in debug mode or not. That is, code such as the following try { Application.Run(new something()); } catch
3
1404
by: Antoon Pardon | last post by:
In a number of cases I have a program that looks like the following. for case in all_cases: try: treat(case) except Exception, ErrInfo: generate_traceback() The idea is to get as much information as possible when something goes wrong but at the same time treat as many cases as possible.
7
1175
by: Gouri.Mahajan7 | last post by:
Hello, I am new to asp.net. when i close the browser programmatically I am getting an application error at the line given below. <param name="SessionID" value="<%= Session %>"/> because of the session no more exists. Can anybody please tell me how to handle that error.
0
7548
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7472
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7743
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6074
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3518
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.