Exception-safe message printing

Fixes #25