[US4394] Fix exception handling and sanitize output