Added try/catch block to avoid errors when stderr is closed.

This should sort the remaining problems with spurious IOExceptions when running the C++ simulator.