Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11867
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <thudfoo@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python,': 0.01; 'exception,': 0.07; 'urllib2': 0.07; 'python': 0.08; 'either.': 0.09; 'subject:error': 0.10; 'users,': 0.13; 'better:': 0.16; 'class:': 0.16; 'occur.': 0.16; 'wrote:': 0.16; 'otherwise,': 0.19; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'correctly.': 0.24; 'specify': 0.24; 'expect': 0.25; 'tried': 0.26; 'import': 0.28; 'print': 0.29; 'recognized': 0.30; 'situations': 0.30; 'error': 0.32; 'does': 0.32; 'anyone': 0.32; 'it.': 0.33; 'probably': 0.33; "can't": 0.33; 'there': 0.33; 'to:addr:python- list': 0.33; 'header:User-Agent:1': 0.34; 'message-id:@gmail.com': 0.34; 'recognize': 0.34; 'try:': 0.34; 'thank': 0.35; 'certain': 0.35; 'skip:" 10': 0.36; 'example,': 0.37; 'statements': 0.37; 'response': 0.37; 'using': 0.37; 'put': 0.37; 'but': 0.37; 'too,': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; 'where': 0.40; 'header :Message-Id:1': 0.61; 'you.': 0.62; 'friday': 0.68; 'august': 0.70; 'subject:... ': 0.84; 'subject:types': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:references:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :message-id; bh=RgckfPXefHSj7/GNgHPXtHsxIyNG7x0/7+JNIEgOJFk=; b=VPBvX/rDtSeavDFyLQKxW2GwUQ4ZiArabENv3w7LxzopmlZ1Rt6JY95zm5w6poakeQ wsOxxIkWLH1vnnQ89ir4tO3vn+5so4+S3x3RxGcAavqJ27nNemRdD7N+hZuANhwNOIHZ g1ura7dipTk5gADI4ue8PuoS86exXJdty0MhQ= |
| From | xDog Walker <thudfoo@gmail.com> |
| To | python-list@python.org |
| Subject | Re: try... except with unknown error types |
| Date | Fri, 19 Aug 2011 12:22:35 -0700 |
| User-Agent | KMail/1.9.5 |
| References | <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> |
| In-Reply-To | <58958843-AE74-44BB-B5E3-96D7A37D779E@mssm.edu> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset="iso-8859-1" |
| Content-Transfer-Encoding | 7bit |
| Content-Disposition | inline |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.232.1313781831.27778.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1313781831 news.xs4all.nl 23922 [2001:888:2000:d::a6]:36144 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:11867 |
Show key headers only | View raw
On Friday 2011 August 19 12:09, Yingjie Lin wrote:
> Hi Python users,
>
> I have been using try...except statements in the situations where I can
> expect a certain type of errors might occur. But sometimes I don't exactly
> know the possible error types, or sometimes I just can't "spell" the error
> types correctly. For example,
>
> try:
> response = urlopen(urljoin(uri1, uri2))
> except urllib2.HTTPError:
> print "URL does not exist!"
>
> Though "urllib2.HTTPError" is the error type reported by Python, Python
> doesn't recognize it as an error type name. I tried using "HTTPError" alone
> too, but that's not recognized either.
>
> Does anyone know what error type I should put after the except statement?
> or even better: is there a way not to specify the error types? Thank you.
You probably need to import urllib2 before you can use urllib2.HTTPError.
Otherwise, you can try using the base class:
except Exception, e:
--
I have seen the future and I am not in it.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: try... except with unknown error types xDog Walker <thudfoo@gmail.com> - 2011-08-19 12:22 -0700 Re: try... except with unknown error types Mel <mwilson@the-wire.com> - 2011-08-19 17:22 -0400
csiph-web