Catch daemon exceptions. This commit fixes #2188.