Fixes #12. Add on-error event for error handling.