Refactor exception rendering and fix an issue where a stack trace may result in invalid XHTML; closes #1152 and closes #1150 and refs #926