Catch and log all the exceptions.

Fix #46