473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1496

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 experienced run-time error number 3021 on a random basis. ...
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 each routine looks like this: Error_Handler: If...
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. Basically, it works as follows: - adds records...
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 works for me on the system I'm using, apparently...
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 kindly, smriti --- Private Sub cmdOK_Click()
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 it in the before update event. But then I...
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 a document, fill in the blanks and become...
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: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
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 from bytes.com (formerly thescripts.com). Ergo, I...
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 from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.