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

documenting excepetions in Python


In python, how do I know what exceptions a method could raise? Do I
need to look at the source? I don't see this info in the API docs for
any of the APIs I'm using.

Thanks in advance for your help.

Oct 19 '07 #1
3 1053
On Oct 19, 10:32 am, dale_bertr...@yahoo.com wrote:
In python, how do I know what exceptions a method could raise? Do I
need to look at the source? I don't see this info in the API docs for
any of the APIs I'm using.

Thanks in advance for your help.
Read the source, run unit tests, etc. If you write your own methods,
you might consider writing tests beforehand: http://en.wikipedia.org/wiki/Test-driven_development

Sometimes the module's docs will tell you the likely return values,
which can help you know what exceptions to look out for.

Mike

Oct 19 '07 #2
In article <11*********************@y27g2000pre.googlegroups. com>,
da***********@yahoo.com wrote:
In python, how do I know what exceptions a method could raise? Do I
need to look at the source? I don't see this info in the API docs for
any of the APIs I'm using.
Hi Dale,
Usually the docs for a method will list the likely exceptions, but
there's no way to know the full list of possible exceptions except by
testing, testing, testing. Obviously, there's always a chance that
there's a test you didn't think of and therefore an exception
unaccounted for. I think this is a less-than-ideal aspect of Python but
I don't have a suggestion on how to improve it.

Good luck

--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
Oct 19 '07 #3
da***********@yahoo.com a écrit :
In python, how do I know what exceptions a method
s/method/callable/

A method is only a thin wrapper around a function, and functions are
just one kind of callable object (classes are another, and you can
define your own...)
could raise?
Practically speaking, you can't. Since an unhandled exception bubbles up
the call stack, there's no reliable way to know what exception could
happen when calling a function. Now there are quite a lot of
'exceptions' you can expect in some situations - like IOError when
dealing with files, etc.
Do I
need to look at the source?
Would be impractical. Trying to spot each and every exception that could
happen in a real-world call stack is a waste of time IMHO. Just deal
with the ones that:
1/ could obviously happen here (like : a missing key in a dict, a
non-(existing|readable|writable) file, etc,
2/ you can handle at this level

Else, just learn to live with the fact that shit happens.
I don't see this info in the API docs for
any of the APIs I'm using.
Indeed. Most of the time, it would be just meaningless.
Oct 19 '07 #4

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

Similar topics

2
by: Rony | last post by:
A question on python source documentation. Does there exist a standard for documenting code ? I've included here an example generated by pydoc of one of my modules. Is this the right way or is it...
5
by: Isaac Rodriguez | last post by:
Hi, Are there any standarized ways of documenting Python code? When I check the __doc__ attribute of the standard modules, the results are kind of plain. Is everyone using this style? Since...
1
by: strauss.sean | last post by:
I have been asked to begin documenting the ongoing development and changes to a database that I maintain. Not the entry of data; this is about the changes to how tables are restructured, and any...
8
by: Spleenwort | last post by:
With regard to XML comments in c#. I think that #regions should be self-documenting relative to XML comments or that a <region> tag should be defined and auto-inserted when you type #region...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.