Catch errors and log them