refactoring method calculate when error occurs