On Sat, 9 Jun 2007 13:52:19 -0700, Warren Stringer <[EMAIL PROTECTED]> wrote: >Am still trying to hook a NameError exception and continue to run. After a >few more hours of searching the web and pouring over Martelli's book, the >closest I've come is: > >>>> import sys >>>> def new_exit(arg=0): >... print 'new_exit called' >... #old_exit(arg) >... >>>> def hook(type, value, tb): >... print 'hook called with', type >... return >... >>>> sys.excepthook = hook >>>> old_exit = sys.exit >>>> sys.exit = new_exit >>>> a[b]=1 # would like to get new_exit called >hook called with exceptions.NameError >>>> >>>> def test(): >... sys.exit() >... >>>> test() >new_exit called > >The interactive session is different from running in the IDE (am using >ActiveState's Visual Python) which exits just after the `a[b]=1` without >calling hook. > >Am I missing something? Perhaps this is the wrong approach? I want Python to >check a specific set of locals first, before checking globals. For instance: >
Yes. Python doesn't have restartable exceptions. Perhaps you would like to take a look at CL or Smalltalk? Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list