Skip to content

Instantly share code, notes, and snippets.

@satra
Created March 17, 2011 15:54
Show Gist options
  • Save satra/874577 to your computer and use it in GitHub Desktop.
Save satra/874577 to your computer and use it in GitHub Desktop.
In [19]: class A(HasTraits):
foo = Int
def __init__(self, **kwargs):
super(A, self).__init__(**kwargs)
self.on_trait_change(self.raiseerror, 'foo')
def raiseerror(self, obj, name, old, new):
raise Exception('testing exception')
....:
....:
In [26]: a = A()
In [27]: a.foo = 2
Exception occurred in traits notification handler.
Please check the log file for details.
Exception occurred in traits notification handler for object: <__main__.A object at 0x10196e950>, trait: foo, old value: 0, new value: 1
Traceback (most recent call last):
File "/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/Traits-3.6.1-py2.7-macosx-10.5-x86_64.egg/enthought/traits/trait_notifiers.py", line 536, in rebind_call_4
object, trait_name, old, new )
File "/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/Traits-3.6.1-py2.7-macosx-10.5-x86_64.egg/enthought/traits/trait_notifiers.py", line 448, in dispatch
handler( *args )
File "<ipython console>", line 7, in raiseerror
Exception: testing exception
In [42]: try:
a.foo=1
except:
print 'exception_raised'
....:
....:
Exception occurred in traits notification handler for object: <__main__.A object at 0x10196e950>, trait: foo, old value: 2, new value: 1
Traceback (most recent call last):
File "/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/Traits-3.6.1-py2.7-macosx-10.5-x86_64.egg/enthought/traits/trait_notifiers.py", line 536, in rebind_call_4
object, trait_name, old, new )
File "/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/Traits-3.6.1-py2.7-macosx-10.5-x86_64.egg/enthought/traits/trait_notifiers.py", line 448, in dispatch
handler( *args )
File "<ipython console>", line 7, in raiseerror
Exception: testing exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment