473,395 Members | 1,468 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,395 software developers and data experts.

Will Python exceptions be documented?

From whet I can see, Python documentation is lacking a very important
piece of information. Very few functions have documented what
exceptions they raise, and under what cicumstances. Is this a task on
the schedule?
In my opinion, every function that might raise an exception should
state so explicitly in the documentation, even uncaught exceptions
from a subfunction.

I have seen many different examples for catching exceptions from
open(). Which is the right one?

The error from function math.log(0) is a by unpredictable, but at
least that is documentet. What about all the others? math.asin(2),
shutil, os, sys?

All know that asin(2) is wrong, but how do I know that ValueError is
the exception I should catch, and how do I know that is the only one?
(Sorry, try it is the wrong answere here.)
My other issue with is concerning the documentation of the exceptions
themselves. How can I find out that I can use 'filename', 'errno' and
'strerror' for the exception IOError without having to use
dir(IOError())? And is it valid in all versions/platforms?

Since I'm critisising the lack of work, I will voulunteer to help out
with the process. But I will need some guidance and pointers in the
beginning.
Python is too good to have a B+ documentation. We can do better.
Cheers,
Vegard
--
Vegard Bakke

My spelling is wobbly. It's good spelling, but it
wobbles, and the letters get it the wrong places.
Winnie the Pooh
:wq
Jul 18 '05 #1
1 2170
ve****@mail.com (Vegard Bakke) writes:
From whet I can see, Python documentation is lacking a very important
piece of information. Very few functions have documented what
exceptions they raise, and under what cicumstances. Is this a task on
the schedule?
IIRC, yes.
[...] I have seen many different examples for catching exceptions from
open(). Which is the right one?
What examples, specifically? The docs say IOError can be raised.
Just about everything can raise ValueError, TypeError,
KeyboardInterrupt and MemoryError, so they aren't typically
documented. I'm not sure exactly when WindowsError (rather than
something more specific) gets raised.

Not answering your question, but as a BTW: in that particular case, if
you're getting uncontrolled input you might sometimes want to
normalise the exceptions raised by catching everything but a few
exceptions. This is useful because you might not have anticipated
every way that weird input might trip up your code (ie. your code may
be buggy). See this recipe and my comment

http://aspn.activestate.com/ASPN/Coo.../Recipe/101853
In fact, I didn't show the try / finally needed to close the file
there, so it should really be:

import traceback
from cStringIO import StringIO

DEBUG = True

def debug(msg):
print msg

def load(filename):
f = open(filename)
try:
try:
# Some code that might raise IOError, or another exception that you
# weren't expecting, if the user is imaginitive enough...
except (AssertionError, KeyboardInterrupt, IOError):
# NOTE WELL the brackets around the exception classes -- an except
# with two arguments means something quite different!
raise
except:
if DEBUG:
f = StringIO()
traceback.print_exc(None, f)
debug("uncaught exception:\n%s" % f.getvalue())
raise IOError, "invalid file '%s'" % filename
finally:
f.close()

load("/some/nonsense/file.txt")

The error from function math.log(0) is a by unpredictable, but at
least that is documentet. What about all the others? math.asin(2),
shutil, os, sys?

All know that asin(2) is wrong, but how do I know that ValueError is
the exception I should catch, and how do I know that is the only one?
(Sorry, try it is the wrong answere here.)
For the math module, the log(0) situation applies. From the 2.3
library docs for the math module:

Note: The math module consists mostly of thin wrappers around the
platform C math library functions. Behavior in exceptional cases is
loosely specified by the C standards, and Python inherits much of
its math-function error-reporting behavior from the platform C
implementation. As a result, the specific exceptions raised in
error cases (and even whether some arguments are considered to be
exceptional at all) are not defined in any useful cross-platform or
cross-release way. For example, whether math.log(0) returns -Inf or
raises ValueError or OverflowError isn't defined, and in cases
where math.log(0) raises OverflowError, math.log(0L) may raise
ValueError instead.

My other issue with is concerning the documentation of the exceptions
themselves. How can I find out that I can use 'filename', 'errno' and
'strerror' for the exception IOError without having to use
dir(IOError())? And is it valid in all versions/platforms?
That's documented under the base class, EnvironmentError.

Since I'm critisising the lack of work, I will voulunteer to help out
with the process. But I will need some guidance and pointers in the

[...]

Great. I'd say just submit some specific doc patches with the
knowledge you already have (as long as you make it clear where you're
unsure). Since that shows you're prepared to do some work on it, it's
likely to get you feedback from the people who know all the details
but don't have time to work on it themselves. Of course, the core
people are probably particularly busy with 2.3 ATM, so don't expect a
rapid response.
John
Jul 18 '05 #2

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

Similar topics

1
by: Craig Ringer | last post by:
QOTW: "Such infrastructure building is in fact fun and instructive -- as long as you don't fall into the trap of *using* such complications in production code, where Python's simplicity rules;-)."...
1
by: Milan Gornik | last post by:
Hello guys, I consulted both MSDN and Borland Builder's documentation to try to find something about this, but I haven't found it. I saw that both VC++ and Builder support different kinds of...
22
by: Drew | last post by:
How do I know which exceptions are thrown by certain methods? For example, reading a file might throw an IO Exception, etc. In Java, the compiler won't even let you compile unless you put your...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 378 open ( +3) / 3298 closed (+34) / 3676 total (+37) Bugs : 886 open (-24) / 5926 closed (+75) / 6812 total (+51) RFE : 224 open...
5
by: Rennie deGraaf | last post by:
I know that if an exception is thrown from a destructor while unwinding the stack because of another exception, terminate() is called (FAQ 17.3). How exactly does this rule work? Is it acceptable...
7
by: JackPot | last post by:
Actually, I'm interested in learning where the different types of exceptions are documented for a specific type of class, let us say for instance classes in the System.Net.Mail Namespace. Shouldn't...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
34
by: Drake | last post by:
I have a general question of Python style, or perhaps just good programming practice. My group is developing a medium-sized library of general-purpose Python functions, some of which do I/O....
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
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...

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.