Exception not raised

Diez B. Roggisch deets at nospam.web.de
Fri Feb 24 12:23:54 EST 2006


Michele Petrazzo wrote:

> Simple example extract from my code:
> 
> #code
> def test():
> print type(t_fields), 11 in t_fields
> print t_fields[11]
> print "I'm here"
> 
> print "ok"
> test()
> print "ok"
> #end code
> 
> Output:
> 
> ok
> <type 'dict'> False
> 
> Here I see only one "ok" and not the "I'm here". The interpreter stop to
> run here, but the application continue to work!


Not here:

t_fields = {}
#code
def test():
  print type(t_fields), 11 in t_fields
  print t_fields[11]
  print "I'm here"

print "ok"
test()
print "ok"
#end code

Gives me 

python2.4 /tmp/test.py
ok
<type 'dict'> False
Traceback (most recent call last):
  File "/tmp/test.py", line 9, in ?
    test()
  File "/tmp/test.py", line 5, in test
    print t_fields[11]
KeyError: 11


So - whatever you do, there must be some other code capturing that
exception. Maybe you don't use dict, but a subclass of it?

Diez



More information about the Python-list mailing list