Add error handling to a thread global