Moving code that throws exception into the begin-rescue block