473,320 Members | 1,861 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,320 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 1054
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.