Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15791 > unrolled thread

Re: try - except. How to identify errors unknown in advance?

Started byTerry Reedy <tjreedy@udel.edu>
First post2011-11-16 16:18 -0500
Last post2011-11-16 16:18 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: try - except. How to identify errors unknown in advance? Terry Reedy <tjreedy@udel.edu> - 2011-11-16 16:18 -0500

#15791 — Re: try - except. How to identify errors unknown in advance?

FromTerry Reedy <tjreedy@udel.edu>
Date2011-11-16 16:18 -0500
SubjectRe: try - except. How to identify errors unknown in advance?
Message-ID<mailman.2784.1321478316.27778.python-list@python.org>
On 11/16/2011 11:57 AM, Frederic Rentsch wrote:

> If I don't know in advance which error to expect, but on the contrary
> want to find out which error occurred, I can catch any error by omitting
> the name:
>
> 	except: (handle)
>
> But now I don't have access to the error message 'e'. I'm sure there's a
> way and it's probably ridiculously simple.

Bare except is a holdover from when exceptions could be strings rather 
than an instance of a subclass of BaseException. A Python 3 interpreter 
in effect runs code within a try-except block something like this:

try:
     <your code>
except BaseException as __exception__:
     <print traceback and exit>

However, use Exception instead of BaseException in your code unless you 
REALLY know what you are doing and why.

-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web