[runtime] Add public API to set the pending exception. (#7759)