when error occur should exit from function