rearranged try except block