make logic correctly when unrolling memory if encounter exceptions