Catching user defined exceptions from foreign modules

Derek Basch dbasch at
Mon Sep 30 17:59:40 CEST 2002

You were correct that the test1 module shouldn't have
worked at all. I needed to change the first line to:

from test2 import TestError, TryItOut

I had test2 open in the PythonWin IDE so it was
already in the namespace.
Which brings me back to my original issue of why it
works here and not in my larger module. Is it normal
to have to import user defined exceptions? I dont
rememeber having to import any of the built in
exceptions. So, here is the output of the fixed test1:


Am I doing this all wrong?
Derek Basch

Derek Basch fed this fish to the penguins on Sunday 29
September 2002 
07:22 pm:

> I know that TestError has been imported because I
> put a "print TestError" before the except clause in
> test1 and I get "test2.TestError". Can anyone tell
> why I am having to put the test2.TestError instead
> just TestError? It confuses me even further that my
> small test modules work like I would expect and it
> doesn't work on the larger modules.

I don't even see why "test1" is working. You
explicitly import the 
exception by name, but you didn't bring in
"TryItOut"... That alone 
should have raised an exception.

[wulfraed at b... wulfraed]$ python
Traceback (most recent call last):
File "", line 14, in ?
File "", line 7, in run
tryitout = TryItOut()
NameError: global name 'TryItOut' is not defined

Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!

More information about the Python-list mailing list