wrap stdout stream write in try/catch