More thorough exception handling

This change uses the enclosed-exceptions package to run user-provided
callbacks safely, catching (and ignoring) all generated exceptions.