Error trap with retry