Reduce the code in the try…except.