Help with trapping an exception

Roger Binns rogerb at
Tue Aug 24 04:14:52 CEST 2004

pythos wrote:
> not defined, I easily figured out the problem.  But I need to use
> "try" and "except" to catch the exception, otherwise my program will
> end abruptly without finishing.  So how can I see the "NameError:
> global name 'Environment' is not defined" message in the "except"
> section of my code?  A call to sys.exc_info() doesn't show it.  Is
> there another function I can use?  Thanks.

I suggest using this code from the Python cookbook:

I also strongly recommend getting the dead tree version as
well.  That recipe and many others are in it, and it is all
well laid out with lots of good discussion.


More information about the Python-list mailing list