fix exception catching logic.