472,338 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,338 software developers and data experts.

Error Trapping

I ran the following program to retrieve entries from the windows
registry on Windows XP:
import win32api, win32con
aReg = win32api.RegConnectRegistry(None,
win32con.HKEY_CURRENT_USER)
aKey = win32api.RegOpenKeyEx(aReg,
r"Software\Microsoft\Internet Explorer\PageSetup")
for i in range(100):
Name, Data, Type = win32api.RegEnumValue(aKey, i)
print "Index=(", i,") Name=[",
Name,"] Data=[",Data,"]
Type=[",Type,"]"
win32api.RegCloseKey(aKey)

This is the program output:

[code:1:8bb6fccb25]Index=( 0 ) Name=[ header ]
Data=[ &w&bPage &p of &P ] Type=[ 1
]
Index=( 1 ) Name=[ footer ] Data=[
&u&b&d ] Type=[ 1 ]
Index=( 2 ) Name=[ margin_bottom ] Data=[ 0.750000
] Type=[ 1 ]
Index=( 3 ) Name=[ margin_left ] Data=[ 0.750000
] Type=[ 1 ]
Index=( 4 ) Name=[ margin_right ] Data=[ 0.750000
] Type=[ 1 ]
Index=( 5 ) Name=[ margin_top ] Data=[ 0.750000
] Type=[ 1 ]

Traceback (most recent call last):
File "F:/temp/Python Test Folder/Read Windows Registry
Entries (No error trapping).py", line 5, in -toplevel-
Name, Data, Type = win32api.RegEnumValue(aKey, i)
error: (259, 'PyRegEnumValue', 'No more data is
available.')[/code:1:8bb6fccb25]

I received an error because I tried to read past the last entry for
this key. The following is a modified version of the program to trap
any error on key entry retrieval:

[code:1:8bb6fccb25]import win32api, win32con, sys
aReg = win32api.RegConnectRegistry(None,
win32con.HKEY_CURRENT_USER)
aKey = win32api.RegOpenKeyEx(aReg,
r"Software\Microsoft\Internet Explorer\PageSetup")
for i in range(100):
try:
Name, Data, Type = win32api.RegEnumValue(aKey, i)
print "Index=(", i,") Name=[",
Name,"] Data=[",Data,"]
Type=[",Type,"]"
except:
break
win32api.RegCloseKey(aKey)[/code:1:8bb6fccb25]

This is the program output:

[code:1:8bb6fccb25]Index=( 0 ) Name=[ header ]
Data=[ &w&bPage &p of &P ] Type=[ 1
]
Index=( 1 ) Name=[ footer ] Data=[
&u&b&d ] Type=[ 1 ]
Index=( 2 ) Name=[ margin_bottom ] Data=[ 0.750000
] Type=[ 1 ]
Index=( 3 ) Name=[ margin_left ] Data=[ 0.750000
] Type=[ 1 ]
Index=( 4 ) Name=[ margin_right ] Data=[ 0.750000
] Type=[ 1 ]
Index=( 5 ) Name=[ margin_top ] Data=[ 0.750000
] Type=[ 1 ][/code:1:8bb6fccb25]

The latter program will trap any error resulting from trying to
retrieve the key values. What I want to do is to specifically trap
the error denoting that there is no more data available so I can
continue executing more code as oppose to aborting the program. if
the error is something other than no more data available, then I want
to abort the program with an error message.

What code is needed to specifically trap the "no more data is
available" error?

Thank you in advance for your help!

Jul 2 '06 #1
0 1419

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

Similar topics

9
by: Robert Wing | last post by:
I support an MS Access application in which errors are trapped using the On Error statement. Just recently, the users of this system have...
2
by: Steve Richfield | last post by:
My error handler works GREAT. However, VBA seems to have some bugs/features that are causing it fits. The little snippet that I put at the end of...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. ...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that...
3
by: Smriti Dev | last post by:
Hi There, I have the following code and when I try to run it, I get a type mismatch error. I would really appreciate your help with this. Thanks...
2
by: Bill Stock | last post by:
I have a subform which is causing a 3314 (Field can't contain a null value because required is set to True) error. I solved this problem by trapping...
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.