Fix the exception handling of Terminate API