Issue #27348: Merge exception formatting fix from 3.5 into 3.6