[Tutor] Exception Handling and Stack traces

Michael Powe michael at trollope.org
Fri Sep 10 16:34:44 CEST 2010


On Fri, Sep 10, 2010 at 03:50:57PM +0200, Evert Rol wrote:

> This is a bit of a guess, but as far as I know, you can catch exceptions like that. 
> Try:
 
> try:
>     data = opener.open(url)
> except urllib2.URLError as msg:
>     print msg
>     sys.exit(1)
 
> If you're using an older version of Python, you'll need:
> 
> try:
>     data = opener.open(url)
> except urllib2.URLError, msg:
>     print msg
>     sys.exit(1)
 
> In your example, you are *creating* an exception (but doing nothing
> with it; I have no idea what happens if you have a line like "except
> <Exception instance>". Perhaps it tries to compare one on one with
> that instance, but if it compares by id, that will not work).  In
> this way, you're not catching the exception. So, it will be pass
> your except clause, and just do what it always does: print the whole
> exception's traceback. Which is probably what you're seeing.

Hello,

Thanks for the reply.  As I indicated in the other message I just
wrote, the format I used is one I took straight from the
documentation. Of course, there may be assumptions in the documented
examples that I am not aware of.

It looks like you and Peter have pulled me out of the ditch and for
that I am grateful.

Thanks.

mp

-- 
Michael Powe		michael at trollope.org		Naugatuck CT USA
It could have been an organically based disturbance of the brain --
perhaps a tumor or a metabolic deficiency -- but after a thorough
neurological exam it was determined that Byron was simply a jerk.  
-- Jeff Jahnke, runner-up, Bulwer-Lytton contest
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20100910/8eaf8d0f/attachment.pgp>


More information about the Tutor mailing list