Wrap some cases where exceptions can be thrown.
Merge pull request #313 from glowe/wrap-exceptions

Wrap some cases where exceptions can be thrown.