Catch exceptions in loop

Catch exceptions and log exceptions. This allows loop to keep running as
well as diagnosis errors.