Using tryCatch to handle errors