Add exception handle for multithread case.