handling thread errors