473,811 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1070
On Oct 19, 10:32 am, dale_bertr...@y ahoo.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************ *********@y27g2 000pre.googlegr oups.com>,
da***********@y ahoo.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***********@y ahoo.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|reada ble|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
1510
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 overkill ? Comments are appreciated Thanks, Rony
5
1969
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 Python is a very powerful language parsing strings, replacing expressions, and processing XML, I was wondering if people documents the code using constructs similar to JavaDoc and then use some functions to display the documentation with a little...
1
1543
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 new (or changes to existing) queries, forms, all objects. Has anyone here done this sort of thing before? Does anyone do this on a regular basis? Finally -- how do you determine the skeleton structure of a database? Certainly, the brute...
8
1760
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 (blah, blah). Anyone have any suggestions for having regions and their comments show up in XML comments...
0
9727
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.