Catching user defined exceptions from foreign modules

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


Everyone,
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:

test2.TestError
fudge

Am I doing this all wrong?
Thanks,
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
can
> put a "print TestError" before the except clause in
> test1 and I get "test2.TestError". Can anyone tell
me
> why I am having to put the test2.TestError instead
of
> 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 test1.py
Traceback (most recent call last):
File "test1.py", line 14, in ?
letitrip.run()
File "test1.py", line 7, in run
tryitout = TryItOut()
NameError: global name 'TryItOut' is not defined


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com




More information about the Python-list mailing list