Move if into try