enthought/enaml — pull request #28 by corranwebster (2011-11-16 19:46:06+00:00)
Title: Traits exceptions

Exceptions raised by traits validation within Fields were not being caught because the actual model values were being set inside a traits notification. This branch fixes the problem by creating a context manager which modifies the Traits notification exception handling to catch the errors, runs the critical code, and then unsets it.

I also added a context manager to simplify tracking error state in controls.

These new features are available on Controls and their subclasses via capture_exceptions() and capture_notification_exceptions() methods which generate the appropriate context managers. Control writers who need to manage error state should probably use them. eg.

with shell_obj.capture_notification_exceptions():
value = shell_obj.converter.from_component(self.getValue()) # this may raise exceptions
shell.value = value # and this may raise an exception inside a traits notification, which we want to get

We also add a toolkit callback for inspecting any exceptions raised to assist debugging, etc.