fix crash issue when exception occurs