Improved thread error handling.