Catch errors rather than crashing.

Hopefully fixes #97.