"Pete" <pkoe...@xs4all.nl> wrote

One thing though - I noticed that when an exception is raised in the
callback function, that exception doesn't actually "show up" in the
calling program.

Yes it does and Steven has answered that so maybe you are clear now.

But just to clarify, when you set a callback there is no guarantee that the callback gets used immediately so the exception will not necessarily appear in the setting function, it will appear in the calling function.


cb = []

def setcb(f):
   cb.append(f)

def fireworks():
   try:
      for f in cb: print f()    # call them all now
  except:
       print 'a callback failed'

def myFunc()
    setcb('lambda : len(cb))
    setcb('lambda : 42)
    setcb('lambda : 66)
    setcb('lambda : 12/0)   #oops!

myFunc()
fireworks()

Here any exceptions in the callback functions won't appear until
the fireworks function, they will not show up in myFunc.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to