Event-based error handler

This is still a work-in-progress and is not ready for merging but would appreciate comments from @jamesls and @toastdriven on basic approach.