Nieuwsgroepen: comp.lang.python
Van: James Stroud <jstr...@ucla.edu>
Datum: Fri, 03 Mar 2006 15:44:23 -0800
Lokaal: za 4 mrt 2006 00:44
Onderwerp: Re: How to except the unexpected?
Rene Pijlman wrote: The relevant lines of urllib2, for example, look as such: > One of the things I dislike about Java is the need to declare exceptions > as part of an interface or class definition. But perhaps Java got this > right... > I've writen an application that uses urllib2, urlparse, robotparser and > How do you program robustly with these modules throwing all those > A catchall seems like a bad idea, since it also catches AttributeErrors class URLError(IOError): This suggests that catching URLError should have caught your HTTPError, E.g.: py> class BobError(Exception): pass Now, % cat httplib.py | grep -e '^\s*class' produces the following at one point in its output: class HTTPException(Exception): Which suggests that "try: except HTTPException:" will be specific enough The following, then, should catch everything you mentioned except the try: But it seems to me that working with the internet as you are doing is James Je moet je aanmelden voordat je berichten kunt plaatsen.
Als je een bericht wilt verzenden, moet je eerst deelnemen aan deze discussiegroep.
Werk je bijnaam bij op de pagina met abonnementsinstellingen voordat je een bericht plaatst.
Je hebt geen toestemming om berichten te plaatsen.
| ||||||||||||||