Catch unhandled exceptions and log them.