You can put this whole thing in a begin rescue block.