Add user-specified action on failure mechanism

This commit allows users to provide application-specific behavior,
e.g., calling into a logging framework.