Move if outisde try/except block