refactor exception handle